【发布时间】:2016-04-23 10:03:38
【问题描述】:
我在 C++ 中有一个数组形式的矩阵,想将它传递给一个用 Rust 编写的共享库函数。我有这样的东西
#![crate_type = "dylib"]
extern crate libc;
use libc::c_void;
extern crate nalgebra as na;
use na::DMatrix2;
#[no_mangle]
pub extern "C" fn rust_fn(p_data: *const c_void, sizex: usize, sizey: usize) {
let matrix = DMatrix2::from_row_vector(sizey, sizex, p_data);
// Do something usefull with the matrix
}
由于我将c_void 传递给from_row_vector(),因此无法编译。
我怎样才能做到这一点?
矩阵是一个双精度数组,但我试图保持接口通用,所以我也可以从例如调用函数。蟒蛇。
我不想在从函数返回时释放矩阵(我想借用,而不是拥有矩阵)。
【问题讨论】:
标签: python c++ matrix rust ffi