从Rust调用C ++类方法时出现问题

问题描述

以下代码是由bindgen生成的。


    extern "C" {
        #[doc = "MoraComm Properties"]
        #[link_name = "\u{1}_ZN22MoraCommManagerWrapped10propertiesEj"]
        pub fn MoraCommManagerWrapped_properties(
            this: *mut MoraCommManagerWrapped,deviceNumber: ::std::os::raw::c_uint,) -> MoraCommPropertiesWrapped;
    }
    impl MoraCommManagerWrapped {
        #[inline]
        pub unsafe fn properties(
            &mut self,) -> MoraCommPropertiesWrapped {
            MoraCommManagerWrapped_properties(self,deviceNumber)
        }
        #[inline]
        pub unsafe fn new() -> Self {
            let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
            MoraCommManagerWrapped_MoraCommManagerWrapped(__bindgen_tmp.as_mut_ptr());
            __bindgen_tmp.assume_init()
        }
    }
    
    fn main() {
           unsafe {
             let mut mgr: MoraCommManagerWrapped = MoraCommManagerWrapped::new();
             let p =   mgr.properties(0); // <-- seg fault
        }
    }

运行main时,出现段故障。

我在C ++端添加了日志记录,这表明this指针的值等于deviceNumber arg的值。

我调用另一个属于同一bindgen生成的绑定的类,并且它起作用。

有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...