【发布时间】:2022-01-25 03:56:26
【问题描述】:
我一直在努力学习 Rust 语言。我已经设法创建了一些简单的命令行应用程序,但现在我要继续看看是否可以创建一个使用图形界面的应用程序。我研究了几个 GUI 库,包括 iced 和 Qt API,但都没有成功。我最近登陆 GTK。我从 gtk crate 文档中获取了示例
https://gtk-rs.org/gtk3-rs/stable/latest/docs/gtk/
该页面上没有关于将什么放入 Cargo.toml 文件的信息,所以我一直在尝试弄清楚。到目前为止,我在网上找到的答案根本没有帮助。于是我去了 crates.io 并获取了最新版本的 gtk crate,0.14.3,并将其放入 toml 中。
[package]
name = "gtkhello"
version = "0.1.0"
authors = ["brian"]
edition = "2018"
[dependencies]
gtk = "0.14.3"
这是示例程序,原封不动地从文档中复制。
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow};
fn main() {
let app = Application::builder()
.application_id("org.example.HelloWorld")
.build();
app.connect_activate(|app| {
// We create the main window.
let win = ApplicationWindow::builder()
.application(app)
.default_width(320)
.default_height(200)
.title("Hello, World!")
.build();
// Don't forget to make all widgets visible.
win.show_all();
});
app.run();
}
当我尝试使用 cargo 构建它时,库的编译失败。如果库本身无法编译,我不知道如何继续。以下是错误:
[brian@localhost gtkhello]$ cargo build
Compiling glib-macros v0.14.1
Compiling gdk-pixbuf-sys v0.14.0
error[E0658]: `#[doc(alias)]` is experimental
--> /home/brian/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-macros-0.14.1/src/clone.rs:202:1
|
202 | #[doc(alias = "get_full_ident")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #50146 <https://github.com/rust-lang/rust/issues/50146> for more information
error[E0658]: `#[doc(alias)]` is experimental
--> /home/brian/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-macros-0.14.1/src/clone.rs:248:1
|
248 | #[doc(alias = "get_keyword")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #50146 <https://github.com/rust-lang/rust/issues/50146> for more information
error[E0658]: `#[doc(alias)]` is experimental
--> /home/brian/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-macros-0.14.1/src/clone.rs:366:1
|
366 | #[doc(alias = "get_expr")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #50146 <https://github.com/rust-lang/rust/issues/50146> for more information
error[E0658]: `#[doc(alias)]` is experimental
--> /home/brian/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-macros-0.14.1/src/clone.rs:413:1
|
413 | #[doc(alias = "get_return_kind")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #50146 <https://github.com/rust-lang/rust/issues/50146> for more information
error[E0658]: `#[doc(alias)]` is experimental
--> /home/brian/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-macros-0.14.1/src/clone.rs:474:5
|
474 | #[doc(alias = "get_closure")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #50146 <https://github.com/rust-lang/rust/issues/50146> for more information
error[E0658]: `#[doc(alias)]` is experimental
--> /home/brian/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-macros-0.14.1/src/clone.rs:579:1
|
579 | #[doc(alias = "get_closure")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #50146 <https://github.com/rust-lang/rust/issues/50146> for more information
Compiling gdk-sys v0.14.0
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0658`.
error: could not compile `glib-macros`.
To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
我访问了issue 的错误消息中建议的链接,它的结尾是:
bors 于 2020 年 9 月 14 日在 57c5f40 中关闭了这个
所以我想我的问题有几个方面。我应该在 Cargo.toml 文件中添加什么来使这个示例正常工作?我应该如何从这个简单的例子中分支出来,将来如何找到这些信息?如何绕过无法编译的必需板条箱?我如何告诉 cargo 我可以使用实验代码?
最大的问题是“我错过了什么?”
【问题讨论】:
-
你的 Rust 版本是什么?看起来它太旧了,因此不受 gtk-rs 的支持。
-
$ rustc --version rustc 1.43.1