使用x11 crate时如何正确链接到xfixes?

问题描述 投票:0回答:1

我正在尝试构建以下程序:

# Cargo.toml
[package]
name = "xhidecursor"
version = "0.1.0"
edition = "2021"

[dependencies]
x11 = { version = "2.20.0", features = ["xlib"] }
use x11::xfixes::XFixesHideCursor;
use x11::xlib::XDefaultRootWindow;
use x11::xlib::XOpenDisplay;
use x11::xlib::XSync;

fn main() {
    let display;
    let window;

    unsafe {
        display = XOpenDisplay(&0);
        window = XDefaultRootWindow(display);
        XFixesHideCursor(display, window);
        XSync(display, 1);
    }
}

失败的原因是:

$ cargo run
   Compiling xhidecursor v0.1.0 (/home/neumann/xhidecursor)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/tmp/rustc90arZ7/symbols.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.1mqky27w09vwj4k3.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.2hnupqzwx9pp7uzf.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.2ncee6h15dx790kk.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.3wcgezgg5zbsr34g.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.4icvi7j5fuzwog4h.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.4l8ef34cbk2a0uy7.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.ropukbb1bsg3lid.rcgu.o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.37qtt1vkgdsjm1zb.rcgu.o" "-Wl,--as-needed" "-L" "/home/neumann/xhidecursor/target/debug/deps" "-L" "/usr/lib" "-L" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/neumann/xhidecursor/target/debug/deps/libx11-f4fa73bc30743fb8.rlib" "/home/neumann/xhidecursor/target/debug/deps/liblibc-f25e23d2977f32be.rlib" "-Wl,--start-group" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-5670385a2fe8b60b.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fd56ba6dbf7aaecc.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-b8acf8e5c2e85baa.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-1706edefffdca0a2.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-f483302e0b13708e.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-725b0718fc18e1ed.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-de685fcf2157e6fb.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-f613ac3eda05b9ff.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-3de98a7d049af6a1.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-c12183655bdce152.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-0fc7beea925de7e3.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-8c34825485bf59dc.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-ba5f7e926e729d81.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-643de0950163a839.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-539ea2f72ef89687.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-871432094bb4c885.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-ef1a8ee61f2e39bf.rlib" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-f1646747442c1c7b.rlib" "-Wl,--end-group" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-ff283b4bf550fa1c.rlib" "-Wl,-Bdynamic" "-lX11" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/neumann/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: /usr/bin/ld: /home/neumann/xhidecursor/target/debug/deps/xhidecursor-72a51398118483b1.ropukbb1bsg3lid.rcgu.o: in function `xhidecursor::main':
          /home/neumann/xhidecursor/src/main.rs:13: undefined reference to `XFixesHideCursor'
          collect2: error: ld returned 1 exit status
          
  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `xhidecursor` due to previous error

我已经通过在 Cargo.toml 中包含 x11 功能

xlib
解决了类似的链接问题。然而,
x11
板条箱似乎没有提供
"xfixes"
的功能。

链接到 xfixes 的正确方法是什么?

linux rust x11
1个回答
1
投票

结果是

x11
板条箱中的一个错误: https://github.com/AltF02/x11-rs/issues/158

上游已修复,但尚未发布。

© www.soinside.com 2019 - 2024. All rights reserved.