繁体   English   中英

如何将 rust GTK 示例链接到 gtk 板条箱?

[英]How do I link the rust GTK example to the gtk crate?

我一直在尝试学习 rust 语言。 我已经设法创建了一些简单的命令行应用程序,但现在我要继续看看是否可以创建一个使用图形界面的应用程序。 我研究了几个 GUI 库,包括 iced 和 Qt api,但都没有成功。 我最近登陆了 GTK。 我从 gtk 板条箱文档中获取了示例

https://gtk-rs.org/gtk3-rs/stable/latest/docs/gtk/

该页面上没有关于将什么放入 Cargo.toml 文件的信息,所以我一直在试图弄清楚。 到目前为止,我在 web 上找到的答案根本没有帮助。 所以我去了 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

我访问了该问题的错误消息中建议的链接,

https://github.com/rust-lang/rust/issues/50146

它以

“bors 于 2020 年 9 月 14 日在 57c5f40 中关闭了这个”

所以我想我的问题有几个方面。 我应该在 Cargo.toml 文件中添加什么来使这个示例正常工作? 我应该如何从这个简单的例子中分支出来,将来如何找到这些信息? 如何绕过无法编译的必需板条箱? 我如何告诉货物我可以使用实验代码?

最大的问题是“我错过了什么?”

谢谢您的帮助。

引用的功能以前不稳定,但在 1.48.0 版本中稳定。 因此, gtk-rs的最低支持 Rust 版本至少为 1.48.0。

一般而言,如果您看到某些 crate 无法参考“不稳定的特性”进行编译,但相应的跟踪问题已经关闭,这通常意味着您的编译器版本比相关 crate 支持的最低版本旧。 如果跟踪问题是开放的,即该功能尚未稳定,则 crate 可能仅适用于每晚 - 在这种情况下,您必须使用rustup install nightly添加必要的工具链,然后通过rustup default nightly将任一设置设置为全局默认值,或仅为当前项目设置覆盖(最简单的方法是使用rustup override nightly )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM