如果需要,我可能没有正确描述我的问题标题,请编辑它。
我正在尝试创建一个Rust接口,以便与用C编写的LXC库进行交互。
我已经成功调用了一些简单功能,比如lxc_get_version
或lxc_container_new
,但我无法访问struct lxc_container
块中描述的函数。
这是我的代码的一部分:
#[link(name = "lxc")]
extern {
// LXC part
fn lxc_get_version() -> *const c_char;
fn lxc_container_new(name: *const c_char, configpath: *const c_char) -> LxcContainer;
// LXC container parts
fn is_defined(container: &LxcContainer) -> bool;
}
这里出现了一个错误:
note: test.o: In function `LxcContainer::is_defined::heb2f16a250ac7940Vba':
test.0.rs:(.text._ZN12LxcContainer10is_defined20heb2f16a250ac7940VbaE+0x3e): undefined reference to `is_defined'
编辑:我已经将C结构体内的函数称为函数指针。我尝试过搜索类似于“Rust C函数指针”的内容,但没有找到相关信息。
is_defined
,因为我无法将LxcContainer结构体作为*LxcContainer传递给函数。会出现解引用错误。您能否在您的回答中添加一些函数指针调用的示例?谢谢。 - bbrodriges