Closed lattice0 closed 3 years ago
For anyone who runs into this issue, you need to add an explicit dependency on gio to your Cargo.toml, and import gio::prelude::*. The extern crate statements are no longer required in this case when using Rust 2018 edition.
gtk already depends on gio, however it doesn't re-export the crate so it's unavailable unless you explicitly add a dependency in Cargo.toml. The connect_activate() used in the examples is defined in gio::ApplicationExt, and similarly run() is in gio::ApplicationExtManual, which is why this is needed. As noted in https://gtk-rs.org/docs-src/tutorial/gnome_and_rust you need to explicitly import the traits containing various methods you wish to use, which is why this is needed.
It might be a good idea to re-export dependent crates (like gio, gdk, atk, etc) from gtk to avoid having to explicitly specify these libraries in Cargo.toml. rust-qt apparently does this: "Each crate re-exports its dependencies, so, for example, you can access qt_core as qt_widgets::qt_core without adding an explicit dependency." (https://rust-qt.github.io/qt/getting_started/). This would then allow importing gtk::gio::prelude::* in this example without needing the explicit gio dependency in Cargo.toml. In general unless you're writing library code for one of these layers directly I don't think importing them via gtk would really be an issue.
Yeah that would happen if @lucaszanella didn't just get rid of the two extern crate
but also the use gio::prelude::*
. That one is required for this to work.
Thanks @sagara- !
I'm trying to build basic.rs: https://github.com/gtk-rs/examples/blob/e7cf9f56e086864ff6f9270216b2ba0416e24648/src/bin/basic.rs
and I'm getting:
I took off the 2
extern crate
because I've read it's old. I don't know whatgio
is, so I only linkedgtk
on Cargo:What is wrong?