如何解决如何在macOS中编译Rust的no_mangle函数调用C函数
我写了下面的Rust函数,可以从C调用C函数。
hasRoles
我在macOS中编译了代码,然后……
#![crate_type = "cdylib"]
#[no_mangle]
pub fn foo() {
unsafe {
bar();
};
}
extern "C" {
pub fn bar();
}
这是在macOS中发生的,但在Linux中没有。
如何在macOS中编译代码?
我的clang版本是$ rustc src/lib.rs
error: linking with `cc` failed: exit code: 1
|
= note: "cc" …
= note: Undefined symbols for architecture x86_64:
"_bar",referenced from:
_foo in lib.lib.3a1fbbbh-cgu.0.rcgu.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: aborting due to previous error
。
编辑:
我想像这样在C语言中使用上述Rust函数:
clang-1103.0.32.62
因此,我想我无法为extern void foo();
int main() {
foo();
}
void bar() {
}
指定#[link(...)]。
(也就是说,我想在Rust中为C程序编写一个插件。)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。