Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么Rust找不到wl\u显示\u获取\u注册表?_Rust_Wayland - Fatal编程技术网

为什么Rust找不到wl\u显示\u获取\u注册表?

为什么Rust找不到wl\u显示\u获取\u注册表?,rust,wayland,Rust,Wayland,在编写代码以使用Wayland客户端API时,Rust似乎无法找到wl\u display\u get\u registry符号。文件的objdump也找不到符号。然而,用GCC编译的C程序能够找到符号 为什么C程序能找到符号,而Rust却找不到?如何修复Rust程序以查找符号 操作系统:Ubuntu 18.04 LTS 生锈 建造 rustc-o wayland main.rs 输出 错误:与'cc'链接失败:退出代码:1 | =注意:“cc”“-Wl,--as needed”“-Wl,-z

在编写代码以使用Wayland客户端API时,Rust似乎无法找到
wl\u display\u get\u registry
符号。文件的objdump也找不到符号。然而,用GCC编译的C程序能够找到符号

为什么C程序能找到符号,而Rust却找不到?如何修复Rust程序以查找符号

操作系统:Ubuntu 18.04 LTS

生锈 建造
rustc-o wayland main.rs
输出
错误:与'cc'链接失败:退出代码:1
|
=注意:“cc”“-Wl,--as needed”“-Wl,-z,noexecstack”“-m64”“-L”“/home/myrddin/.rustup/toolschains/stable-x86_/lib/rustlib/x86_64-unknown-linux-gnu/lib”“wayland.main0.rcgu.o”“wayland.main 1.rcgu.o”“wayland.main.2.rcgu.o”“wayland.main3.rcgu.o”“wayland.o”“wayland.main.main4.rcgu.o”“-o”“wayland”“wayland”“wayland.crator.gu.o”“wayland“-Wl,--gc sections”“-pie”“-Wl,-z,relro,-z,nodefaultlibs”“-L”“/home/myrddin/.rustup/toolschains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib”“-L”“wayland client”“-Wl,--start group”“-Wl,--Bstatic”/home/myrddin/.rustup/toolschains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-2da986ecbb2c5327.rlib”“/home/myrddin/.rustup/toolschains/stable-x86_64-unknown-linux-gnu/rustlib/x86_64-unknown-linux-gnu/lib/lib/lib/lib/libpanic\u unwind-57F46848C9F4ee.rlib”/home/myrddin/.rustup/toolstanks/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/lib/liballoc\u jemalloc-23263fe5893322f6.rlib”“/home/myrddin/.rustup/toolstanks/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/lib/lib/lib/libunwind-6ed5262c9a3a3a.rlib/home/myrddin/.rustup/toolschains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_system-99c162b689d4349.rlib”“/home/myrddin/.rustup/toolschains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/lib/lib/lib-cd4155b85267875.rlib”/home/myrddin/.rustup/toolschains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/lib/liballoc-3876ac10aa96a1e3.rlib”“/home/myrddin/.rustup/toolschains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/lib/lib/lib/lib/libstd\unicode-598B0E9AC382E9A.rlib/home/myrddin/.rustup/toolschains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4eabb2b1c31071b8.rlib”“-Wl,--end-group”“/home/myrddin/.rustup/toolschains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu-gnu-gnu/lib/lib/lib/lib/lib编译器内置程序-D7A656735ceae9e.rlib”“-Wl,--l”“-l”“-l”“-l”“-l”“-pthread“-l”“pthread”“-l”“gcc_s”“-l”“c”“-l”“m”“-l”“rt”“-l”“pthread”“-l”“util”“-l”“util”
=注意:wayland.main3.rcgu.o:在函数'main::main'中:
main3-317d481089b8c8fe83113de504472633.rs:(.text.\u ZN4main4main17h52709beaa06fe157E+0x109):对“wl\u显示\u获取\u注册表”的未定义引用
collect2:错误:ld返回了1个退出状态
代码 C 建造
gcc-o wayland-lwayland客户端main.c
输出
已连接到Wayland显示服务器。
从航路显示中检索注册表。
已检索注册表。
已断开与Wayland显示服务器的连接。
代码
#包括
#包括
int main()
{
结构wl_显示*显示;
结构WLU注册表*注册表;
显示=wl\U显示\U连接(空);
如果(显示==NULL)
{
fprintf(stderr,“无法连接到Wayland显示服务器。\n”);
返回1;
}
fprintf(标准输出,“连接到Wayland显示服务器。\n”);
fprintf(stdout,“从航路显示检索注册表。\n”);
注册表=wl\U显示\U获取\U注册表(显示);
if(注册表==NULL)
{
fprintf(stderr,“无法检索注册表。\n”);
}
其他的
{
fprintf(标准输出,“检索到注册表。\n”);
}
wl_显示_断开(显示);
fprintf(标准输出,“与Wayland显示服务器断开连接。\n”);
返回0;
}
objdump
命令
objdump-TC/usr/lib/x86_64-linux-gnu/libwayland-client.so | grep“wl_display*”
输出
000000000000 5F60 g DF.text 0000000000000 275基本wl\u显示\u连接
0000000000006960 g DF.文本00000000000000 78基本wl\U显示\U刷新
0000000000006a90 g DF.文本000000000000000 C基本wl\U显示\U调度
00000000000067b0 g DF.文本00000000000000 42基本wl\u显示\u取消\u读取
00000000000068c0 g DF.text 000000000000000 C基本wl\u显示\u调度\u挂起
0000000000006800 g DF.text 00000000000000 BF基本wl\u显示\u调度\u队列\u挂起
00000000000061e0 g DF.文本00000000000000 57基本wl\U显示\U断开
0000000000006be0 g DF.text 00000000000000 FC基本wl\u显示\u往返\u队列
00000000000068d0 g DF.文本00000000000000 2C基本wl\u显示\u获取\u错误
0000000000005610 g DF.text 00000000000000 31基本wl\u显示\u创建\u队列
0000000000006740 g DF.text 00000000000000 52基本wl\u显示\u准备\u读取\u队列
0000000000006900 g DF.text 00000000000000 51基本wl\u显示\u获取\u协议\u错误
000000000000 5DC0 g DF.文本0000000000000 194基本wl\U显示\U连接到\U fd
00000000000069e0 g DF.text 00000000000000 AC基本wl\u显示\u调度\u队列
0000000000006ce0 g DF.文本000000000000000 C基本wl\U显示\U往返
0000000000006250 g DF.文本0000000000000 4F0基本wl\U显示\U读取\U事件
0000000000006240 g DF.文本000000000000000 4基本wl\U显示\U获取\U fd
0000000000 20DCE0 g DO.data.rel.ro 00000000000000 28基本WLU显示界面
00000000000067a0 g DF.文本000000000000000 C基本wl\U显示\U准备\U读取

头文件
wayland client protocols.h
中将
wl\u display\u get\u registry
函数和其他几个函数标记为
static inline
。这说明了C如何能够查看和使用该函数,但Rust却不能

我们必须将C宏和静态内联函数重新实现为Rust函数:

pub enum WLDisplay {}
pub enum WLProxy {}
pub enum WLRegistry {}

const WL_DISPLAY_GET_REGISTRY: ::std::os::raw::c_uint = 1;

#[link(name = "wayland-client")]
extern "C" {
    #[no_mangle]
    static wl_registry_interface: WLInterface;

    pub fn wl_display_connect(name: *const ::std::os::raw::c_char) -> *mut WLDisplay;
    pub fn wl_display_disconnect(display: *mut WLDisplay) -> ();

    pub fn wl_proxy_marshal_constructor(
        proxy: *mut WLProxy,
        opcode: ::std::os::raw::c_uint,
        interface: *const WLInterface,
    ) -> *mut WLProxy;
}

#[repr(C)]
pub struct WLMessage {
    pub name: *const ::std::os::raw::c_char,
    pub signature: *const ::std::os::raw::c_char,
    pub types: *const *const WLInterface,
}

#[repr(C)]
pub struct WLInterface {
    pub name: *const ::std::os::raw::c_char,
    pub version: ::std::os::raw::c_int,
    pub request_count: ::std::os::raw::c_int,
    pub requests: *const WLMessage,
    pub event_count: ::std::os::raw::c_int,
    pub events: *const WLMessage,
}

fn wl_display_get_registry(display: *mut WLDisplay) -> *mut WLRegistry {
    let proxy: *mut WLProxy;

    unsafe {
        proxy = wl_proxy_marshal_constructor(
            display as *mut _ as *mut WLProxy,
            WL_DISPLAY_GET_REGISTRY,
            &wl_registry_interface,
        );
        proxy as *mut _ as *mut WLRegistry
    }
}

fn main() {
    let display: *mut WLDisplay;
    let registry: *mut WLRegistry;

    unsafe {
        display = wl_display_connect(::std::ptr::null());
        if display.is_null() == true {
            eprintln!("Unable to connect to the Wayland display server.");
            return;
        }
        println!("Connected to Wayland display server.");

        println!("Retrieving the registry from the Wayland display.");
        registry = wl_display_get_registry(display);
        if registry.is_null() == true {
            eprintln!("Unable to retrieve registry.");
        } else {
            println!("Registry retrieved.");
        }

        wl_display_disconnect(display);
        println!("Disconnected from Wayland display server.");
    }
}
pub enum WLDisplay {}
pub enum WLProxy {}
pub enum WLRegistry {}

const WL_DISPLAY_GET_REGISTRY: ::std::os::raw::c_uint = 1;

#[link(name = "wayland-client")]
extern "C" {
    #[no_mangle]
    static wl_registry_interface: WLInterface;

    pub fn wl_display_connect(name: *const ::std::os::raw::c_char) -> *mut WLDisplay;
    pub fn wl_display_disconnect(display: *mut WLDisplay) -> ();

    pub fn wl_proxy_marshal_constructor(
        proxy: *mut WLProxy,
        opcode: ::std::os::raw::c_uint,
        interface: *const WLInterface,
    ) -> *mut WLProxy;
}

#[repr(C)]
pub struct WLMessage {
    pub name: *const ::std::os::raw::c_char,
    pub signature: *const ::std::os::raw::c_char,
    pub types: *const *const WLInterface,
}

#[repr(C)]
pub struct WLInterface {
    pub name: *const ::std::os::raw::c_char,
    pub version: ::std::os::raw::c_int,
    pub request_count: ::std::os::raw::c_int,
    pub requests: *const WLMessage,
    pub event_count: ::std::os::raw::c_int,
    pub events: *const WLMessage,
}

fn wl_display_get_registry(display: *mut WLDisplay) -> *mut WLRegistry {
    let proxy: *mut WLProxy;

    unsafe {
        proxy = wl_proxy_marshal_constructor(
            display as *mut _ as *mut WLProxy,
            WL_DISPLAY_GET_REGISTRY,
            &wl_registry_interface,
        );
        proxy as *mut _ as *mut WLRegistry
    }
}

fn main() {
    let display: *mut WLDisplay;
    let registry: *mut WLRegistry;

    unsafe {
        display = wl_display_connect(::std::ptr::null());
        if display.is_null() == true {
            eprintln!("Unable to connect to the Wayland display server.");
            return;
        }
        println!("Connected to Wayland display server.");

        println!("Retrieving the registry from the Wayland display.");
        registry = wl_display_get_registry(display);
        if registry.is_null() == true {
            eprintln!("Unable to retrieve registry.");
        } else {
            println!("Registry retrieved.");
        }

        wl_display_disconnect(display);
        println!("Disconnected from Wayland display server.");
    }
}