./c_src/main: error while loading shared libraries: libcallrust.so: cannot open shared object file: No such file or directory
makefile:5: recipe for target 'run' failed
make: *** [run] Error 127
经查明。在makefile 运行中指定链接目录变量 LD_LIBRARY_PATH可以顺利运行:
$ make run
/home/huangjj27/.cargo/bin/cargo clean
rm -f ./c_src/main
/home/huangjj27/.cargo/bin/cargo build
Compiling libc v0.2.69
Compiling callrust v0.1.0 (/mnt/c/Users/huangjj27/Documents/codes/callrust)
warning: unused import: `libc`
--> src/lib.rs:1:5
|
1 | use libc;
| ^^^^
|
= note: `#[warn(unused_imports)]` on by default
Finished dev [unoptimized + debuginfo] target(s) in 5.83s
/usr/bin/gcc -o ./c_src/main ./c_src/main.c -I./src -L./target/debug -lcallrust
LD_LIBRARY_PATH=./target/debug ./c_src/main
Hello from rust
在 WSL/Linux 环境下 根据页面 第518 - 520页的代码示例,对在c程序中 调用 rust 编译好的 libcallrust.so 文件时出现了如下报错:
经查明。在makefile 运行中指定链接目录变量
LD_LIBRARY_PATH
可以顺利运行:代码错误
Rust版本