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++ *の*もCのFFIを持っているので、そのCのコンパイラと互換性のあるC++のクラス/構造体は、RustからCのように使用できます。 –
ありがとう@Shepmaster今コンパイルされます。それは働いているかもしれませんが、私のOctave helloworldはまだないので、私は100%確信していません。 https://github.com/ctaggart/octh_examples/blob/master/src/lib.rs –
@CameronTaggartわかりませんが、すべての機能で名前のマングリングを防ぐ必要があります。 'Fhelloworld'に'#[no_mangle] 'がありませんか? –