Gtk4 Rust示例text_viewer编译报错及切换Commit后问题求助
gtk4-rs text_viewer示例编译错误解决求助
问题背景
我在测试gtk4-rs主分支的示例代码时,大部分示例都能正常编译运行,但text_viewer示例执行cargo run --bin text_viewer时失败,核心错误是error[E0432]: unresolved import gtk::FileDialog``,提示gtk根模块里没有FileDialog这个项。
我的环境信息:
- 系统:Linux Mint 21.2
- Gtk版本:4.6.6
- 示例目录下的Cargo.toml配置:
[dependencies.gtk] path = "../gtk4" package = "gtk4" features = ["v4_6"]
完整编译错误输出如下:
oz-mint@ozmint-MACH-WX9:~/tmp/gtk4-rs-master/examples$ cargo run --bin text_viewer warning: some crates are on edition 2021 which defaults to `resolver = "2"`, but virtual workspaces default to `resolver = "1"` note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest Skipping git submodule `https://github.com/gtk-rs/gir` due to update strategy in .gitmodules Skipping git submodule `https://github.com/gtk-rs/gir-files` due to update strategy in .gitmodules warning: private item shadows public glob re-export --> gdk4/src/lib.rs:85:1 | 85 | mod functions; | ^^^^^^^^^^^^^^ | note: the name `functions` in the type namespace is supposed to be publicly re-exported here --> gdk4/src/lib.rs:110:9 | 110 | pub use auto::*; | ^^^^^^^ note: but the private item here shadows it --> gdk4/src/lib.rs:85:1 | 85 | mod functions; | ^^^^^^^^^^^^^^ = note: `#[warn(hidden_glob_reexports)]` on by default warning: `gdk4` (lib) generated 1 warning warning: private item shadows public glob re-export --> gtk4/src/lib.rs:148:1 | 148 | mod functions; | ^^^^^^^^^^^^^^ | note: the name `functions` in the type namespace is supposed to be publicly re-exported here --> gtk4/src/lib.rs:105:9 | 105 | pub use auto::*; | ^^^^^^^ note: but the private item here shadows it --> gtk4/src/lib.rs:148:1 | 148 | mod functions; | ^^^^^^^^^^^^^^ = note: `#[warn(hidden_glob_reexports)]` on by default warning: `gtk4` (lib) generated 1 warning Compiling gtk4-rs-examples v0.1.0 (/home/oz-mint/tmp/gtk4-rs-master/examples) error[E0432]: unresolved import `gtk::FileDialog` --> examples/text_viewer/main.rs:7:71 | 7 | use gtk::{gio, glib, Application, ApplicationWindow, Builder, Button, FileDialog, TextView}; | ^^^^^^^^^^ no `FileDialog` in the root For more information about this error, try `rustc --explain E0432`. error: could not compile `gtk4-rs-examples` (bin "text_viewer") due to previous error
另外,我已经测试过官方的Hello World示例,能正常运行,说明Gtk的Rust绑定本身是正常工作的。
尝试解决后的新问题
后来了解到FileDialog是Gtk 4.10及以上版本才有的API,而我当前系统是4.6.6,所以我切换到了一个较早的Commit:
oz-mint@ozmint-MACH-WX9:~/tmp/gtk4-rs$ git checkout 06f5c84c936f046d17a9d5ddd00d64a70f20c056
切换完成后再次运行cargo run --bin text_viewer,又出现了新的错误:找不到cairo-rs包,提示该包被gtk4依赖,但在指定的仓库路径里找不到。
完整错误输出:
oz-mint@ozmint-MACH-WX9:~/tmp/gtk4-rs$ cd examples/ oz-mint@ozmint-MACH-WX9:~/tmp/gtk4-rs/examples$ cargo run --bin text_viewer Updating crates.io index Updating git repository `https://github.com/gtk-rs/gtk-rs` Skipping git submodule `https://github.com/gtk-rs/gir` due to update strategy in .gitmodules Skipping git submodule `https://github.com/gtk-rs/gir-files` due to update strategy in .gitmodules error: no matching package named `cairo-rs` found location searched: https://github.com/gtk-rs/gtk-rs required by package `gtk4 v0.1.0 (/home/oz-mint/tmp/gtk4-rs/gtk4)`
想请教一下,我该怎么调整配置或者操作,才能让text_viewer示例正常编译运行?
内容的提问来源于stack exchange,提问作者ozkanpakdil
相关产品推荐
相关产品推荐

