2
저는 C++ 구조체를 만들고 반환하려고합니다. 컴파일을 시도 할 때 현재 cannot move out of dereference of raw pointer
오류가 발생합니다. 내가 어떻게이 일을 할 수 있는지 아는가?Rust FFI에서 C++ 구조체를 생성하고 반환하는 방법?
#![allow(non_snake_case)]
#![allow(unused_variables)]
extern crate octh;
// https://thefullsnack.com/en/string-ffi-rust.html
use std::ffi::CString;
#[no_mangle]
pub unsafe extern "C" fn Ghelloworld(
shl: *const octh::root::octave::dynamic_library,
relative: bool,
) -> *mut octh::root::octave_dld_function {
let name = CString::new("helloworld").unwrap();
let pname = name.as_ptr() as *const octh::root::std::string;
std::mem::forget(pname);
let doc = CString::new("Hello World Help String").unwrap();
let pdoc = doc.as_ptr() as *const octh::root::std::string;
std::mem::forget(pdoc);
return octh::root::octave_dld_function_create(Some(Fhelloworld), shl, pname, pdoc);
}
pub unsafe extern "C" fn Fhelloworld(
args: *const octh::root::octave_value_list,
nargout: ::std::os::raw::c_int,
) -> octh::root::octave_value_list {
let list: *mut octh::root::octave_value_list = ::std::ptr::null_mut();
octh::root::octave_value_list_new(list);
std::mem::forget(list);
return *list;
}
참고 : C++ * also *는 C FFI를 가지고 있으므로 C에서와 같이 모든 C++ 클래스/구조체가 Rust에서 사용할 수 있습니다. –
Thanks @Shepmaster. 이제 컴파일됩니다. 그것은 효과가 있을지 모르지만, 내 Octave helloworld는 아직 아니므로 100 % 확실하지 않습니다. https://github.com/ctaggart/octh_examples/blob/master/src/lib.rs –
@CameronTaggart 확실치는 않지만, 모든 기능에서 이름 맹 글링을 방지해야합니다. 'Fhelloworld'에'# [no_mangle]'가 없습니까? –