rust - 如何通过链接器-rlink参数?

标签 rust cross-compiling linker-errors

我正在尝试与cross交叉编译一个rust项目。我的项目取决于libcurl。链接器可以找到libcurl .so,但找不到它所依赖的库:
我在跑:

cross build -vv --target=arm-unknown-linux-gnueabihf
这给了我:
  = note: /usr/arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/bin/ld: warning: libnghttp2.so.14, needed by /usr/lib/arm-linux-gnueabihf/libcurl.so, not found (try using -rpath or -rpath-link)
我已经确认其寻找的库存在:
root@80a13d68ad84:/# find /usr/lib -name "libnghttp2.so.14"
/usr/lib/x86_64-linux-gnu/libnghttp2.so.14
/usr/lib/arm-linux-gnueabihf/libnghttp2.so.14
我已经阅读了有关rust build脚本here的信息,可以在其中向库搜索路径添加路径,但这并不能解决问题,这是我的build.rs的样子:
fn main() {
    println!("cargo:rustc-link-search=native=/usr/lib/arm-linux-gnueabihf");
}
该错误提示您使用-rpath或-rpath-link,那么如何在rust中配置rpath?还是有其他方法可以解决此问题?

最佳答案

您可能可以通过使用类似以下的环境变量来指定链接器参数

RUSTFLAGS="-C link-arg=--rpath=..."
Cargo允许在配置文件中放置相同类型的标志(请参阅here),但我不确定cross是否对类似内容具有相同的支持。

关于rust - 如何通过链接器-rlink参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64835913/

相关文章:

rust - 在 Rust 中创建一个连接 HashMap 键的字符串

linux - 如何为window建立一个基于linux的程序?

c - 使用 clock() 测量执行时间

Linux 程序集 "collect2: ld returned 1 exit status"

c++ - 如何在 C++ 中的不同翻译单元之间共享枚举实例?

ios - ios 中体系结构 x86_64 的 undefined symbol

rust - 如何将任意就地操作应用于 &mut 引用?

command-line - 如何通过 Clap 将所有命令行参数传递给另一个程序?

file - 为什么 BufReader::read 并不总是完全填满给定的缓冲区?

android - 如何将 OpenSSL 构建为 Android 的未版本化共享库?