Rust中CC crate示例无法链接C函数的编译错误求助
Rust中CC crate示例无法链接C函数的编译错误求助
嘿,我最近在学用Rust里的CC crate调用C代码,照着官方示例写了代码,但编译一直卡壳,报了链接错误,实在搞不定来求助大家!
我遇到的错误信息是这样的:
error: linking with `cc` failed: exit status: 1 = note: /usr/bin/ld: /home/usr/MAIN_DIR/dir/target/debug/deps/dir-c24b87d5163d50b4.31veb4gx0s10h8ys.rcgu.o: in function `dir::call': /home/usr/MAIN_DIR/dir/src/main.rs:8: undefined reference to `bar_function' /usr/bin/ld: /home/usr/MAIN_DIR/dir/src/main.rs:9: undefined reference to `foo_function' collect2: error: ld returned 1 exit status = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified = note: use the `-l` flag to specify native libraries to link = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)
我的build.rs文件代码大概是这样的(部分内容省略):
fn main() { // 这里是我写的CC构建代码 }
我已经检查过Rust代码里的extern声明,应该是和C函数签名对应的,但就是找不到函数定义。有没有大佬能帮我看看问题出在哪?
备注:内容来源于stack exchange,提问作者recouer
相关产品推荐
相关产品推荐

