我有一个使用介子的基本 gtk-rs 项目。我在 Cargo.toml 文件中包含了 gtk4 crate。当我使用货物运行时,它编译但输出“分段错误”错误(我已经搜索过,但我仍然不知道那是什么)。但是,当我使用介子运行时,它根本拒绝构建。
builddir/
main.p/
build.ninja
src/
main.rs
target/
...
Cargo.toml
Cargo.lock
meson.build
货运.toml
[package]
name = "my-gtk-app"
version = "0.1.0"
edition = "2018"
[dependencies]
gtk = { version = "0.2", package = "gtk4" }
介子.build
project(
'my-gtk-app',
'rust',
version : '0.1',
)
cargo_sources = files(
'Cargo.toml',
'Cargo.lock',
)
gtk = dependency('gtk4', version: '>= 4.0.0')
executable('main', 'src/main.rs', dependencies : gtk)
main.rs
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 window = ApplicationWindow::builder()
.application(app)
.default_width(320)
.default_height(200)
.title("Hello, World!")
.build();
// Show the window.
window.show();
});
app.run();
}
当我使用运行程序时cargo run
,我得到
Finished dev [unoptimized + debuginfo] target(s) in 0.45s
Running `target/debug/my-gtk-app`
1] 73039 segmentation fault cargo run
但是,当我使用 with 运行时meson compile -C builddir
,我得到
ninja: Entering directory `builddir'
[1/1] Compiling Rust source ../src/main.rs
FAILED: main
rustc -C linker=cc --color=always --crate-type bin --crate-name main -g --emit dep-info=main.d --emit link -o main -L/usr/local/Cellar/gtk4/4.4.0/lib -L/usr/local/Cellar/pango/1.48.10/lib -L/usr/local/Cellar/harfbuzz/3.0.0/lib -L/usr/local/Cellar/gdk-pixbuf/2.42.6/lib -L/usr/local/Cellar/cairo/1.16.0_5/lib -L/usr/local/Cellar/graphene/1.10.6/lib -L/usr/local/Cellar/glib/2.70.0_1/lib -L/usr/local/opt/gettext/lib -l dylib=gtk-4 -l dylib=pangocairo-1.0 -l dylib=pango-1.0 -l dylib=harfbuzz -l dylib=gdk_pixbuf-2.0 -l dylib=cairo-gobject -l dylib=cairo -l dylib=graphene-1.0 -l dylib=gio-2.0 -l dylib=gobject-2.0 -l dylib=glib-2.0 -l dylib=intl ../src/main.rs
error[E0433]: failed to resolve: maybe a missing crate `gtk`?
--> ../src/main.rs:1:5
|
1 | use gtk::prelude::*;
| ^^^ maybe a missing crate `gtk`?
error[E0432]: unresolved import `gtk`
--> ../src/main.rs:2:5
|
2 | use gtk::{Application, ApplicationWindow};
| ^^^ maybe a missing crate `gtk`?
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0432, E0433.
For more information about an error, try `rustc --explain E0432`.
ninja: build stopped: subcommand failed.
如果有帮助,我在 MacOS 上。