在目录中,我有一个C文件及其头文件
/ home / test / c_pro
f.c
f.h
libf.so
我已使用以下命令将f.c编译为一个名为libf.so的dll
gcc -c -fPIC f.c -o f.o
gcc f.o -shared -o f.so
我想在我的Rust项目中使用它。
因此在Rust项目中,我有一个build.rs
println!("cargo:rustc-link-search=/home/test/c_pro");
println!("cargo:rustc-link-lib=dylib=f")
当我运行cargo build
时,构建失败并出现以下错误
/home/test/c_pro/f.so: undefined reference to `EC_KEY_new_by_curve_name'
collect2: error: ld returned 1 exit status
在我的文件中,我从openssl进行了一些导入
#include <openssl/bio.h>
#include <openssl/bn.h>
#include <openssl/ecdsa.h>
#include <openssl/obj_mac.h>
并使用这些库中的符号。
关于为什么构建失败的任何想法?我正在遵循官方文档,并依赖2个构建参数
我在这里想念的人们是什么?预先感谢。
编辑+更新:
我按照@Uli Schlachter的指示进行了操作,并且可以编译,但是出现运行时错误,指出未找到libf.so
。
ldd ./target/debug/test_f
libf.so => not found.
有什么想法吗?
使用...编译共享对象
gcc -c -fPIC f.c -o f.o
gcc f.o -shared -o f.so -lssl