Rust 标准库的共享库和静态库在哪里?

Where are the shared and static libraries of the Rust standard library?

我正在尝试使用动态链接编译我的 Rust 项目以减小大小并为应用程序提供 .so(或 Windows 上的 .dll)文件,就像 Qt 为 Android 所做的那样。我阅读 并使用

编译
cargo rustc  -- -C prefer-dynamic

当我 运行 我的程序时,我得到这个错误:

 % target/debug/t_pro 
target/debug/t_pro: error while loading shared libraries: libstd-a021829e87e39dcf.so: cannot open shared object file: No such file or directory

这些库会安装在您选择安装 Rust 的任何地方。我在 macOS 上使用 rustup,所以它们安装在 ~/.rustup/toolchains/*whatever*/lib/ 中。

使用操作系统的工具搜索特定名称的文件。

另请参阅:

  • How to set the environmental variable LD_LIBRARY_PATH in linux

我得到了一个answer on Reddit

rustc --print=sysroot

在我的例子中,.so 文件在 /home/username/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib 中,.rlib 在 /home/username/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib.