rust - fatal error LNK1181 : cannot open input file 'gtk-3.lib'

标签 rust gtk-rs

所以我为 rust 设置了 GTK-rs,我一定是做错了什么,因为当我尝试运行我的代码时,它返回了这个错误,我不知道如何修复它:fatal error LNK1181: cannot open input file 'gtk-3.lib'如果有帮助,我会使用 Eclipse IDE。
更多可能有帮助的数据:
我的环境变量是:

GTK_LIB_DIR=C:\msys64\mingw64\lib
PATH:
  C:\msys64\mingw64\bin
  C:\msys64\mingw64\include
我的 Cargo.toml 文件:
[package]
name = "myapp"
version = "0.1.0"
authors = ["author"]
edition = "2018"

[dependencies.gtk]
version = "0.9.2"
features = ["v3_16"]

[dependencies]
glib = "0.10.2"
gio = "0.9.1"


我使用了一些修改后的示例代码进行测试:
#![allow(non_snake_case)]
extern crate gtk;
extern crate glib;
extern crate gio;

use gio::prelude::*;
use glib::clone;
use gtk::prelude::*;

// When the application is launched…
fn on_activate(application: &gtk::Application) {
    // … create a new window …
    let window = gtk::ApplicationWindow::new(application);
    // … with a button in it …
    let button = gtk::Button::with_label("Hello World!");
    // … which closes the window when clicked
    button.connect_clicked(clone!(@weak window => move |_| window.close()));
    window.add(&button);
    window.show_all();
}

fn main() {
    // Create a new application
    let app = gtk::Application::new(Some("com.github.gtk-rs.examples.basic"), Default::default())
        .expect("Initialization failed...");
    app.connect_activate(|app| on_activate(app));
    // Run the application
    app.run(&std::env::args().collect::<Vec<_>>());
}

最佳答案

在使用 gstreamer 和 gtk Rust 绑定(bind)时,我遇到了与“link.exe”相同的问题。这是我为使程序编译所做的工作。
除了检查“C++ 构建工具”时安装的“默认”工具外,下载 Microsoft 构建工具并安装以下工具。
MS Build Tools Options - credit https://github.com/rust-lang/rust/issues/44787
安装后,确保“C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\bin\Hostx64\x64”在您的环境路径中。
重新启动您的电脑并再次尝试编译。希望它会奏效。但是,如果仍然没有,我建议从 powershell 卸载 Rust

rustup self uninstall
然后以这种方式从 rustup.exe 重新安装 Rust。
  • 运行 rustup.exe
  • 当提示安装选项时,选择“自定义安装”
  • 对于默认主机三元组选项类型
    稳定-x86_64-pc-windows-gnu
  • 其余部分按“默认”选项,然后继续安装。

  • 重新启动你的电脑,程序肯定会编译。

    关于rust - fatal error LNK1181 : cannot open input file 'gtk-3.lib' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64219095/

    相关文章:

    rust - Rust中不同类型的工厂函数

    rust - 导入我自己的标准库时如何避免导入冲突?

    rust - 如何从单击按钮的条目中获取信息?

    Rust 闭包错误 -> ...由当前函数拥有 |捕获移动值 :

    rust - 泛型和关联类型有什么区别?

    rust - Rust借用可能未初始化的变量-作为程序员,这对我来说很明显,它将始终被初始化

    string - 如何在POSIX系统上将OsString转换为u16?

    rust - 连接到 Glade 文件中定义的自定义 GTK 信号

    rust - Gtk-错误 ** : failed to add UI: Error on line 1 char 1: Document must begin with an element

    multithreading - gtk-rs:如何从另一个线程更新 View