rust - 我可以获得 Rust 链接的原生工件的完整路径吗?

标签 rust rust-cargo

我在 Windows 10 上使用 32 位版本的 Rust 1.6 来编译 rustlab .当我运行 cargo build 来构建它时,它说要

link against the following native artifacts when linking against this static library

我确实想这样做。有没有办法获取所用库的完整路径?

PS C:\rs\rustlab> cargo build -v
   Compiling libc v0.2.7
     Running `rustc C:\Users\cameron\.cargo\registry\src\github.com-48ad6e4054423464\libc-0.2.7\src\lib.rs --crate-name libc --crate-typ
e lib -g --cfg "feature=\"default\"" -C metadata=0c94fdfb80c4b805 -C extra-filename=-0c94fdfb80c4b805 --out-dir C:\rs\rustlab\target\deb
ug\deps --emit=dep-info,link -L dependency=C:\rs\rustlab\target\debug\deps -L dependency=C:\rs\rustlab\target\debug\deps --cap-lints all
ow`
   Compiling rustlab v0.1.0 (file:///C:/rs/rustlab)
     Running `rustc src\lib.rs --crate-name rustlab --crate-type staticlib --crate-type dylib -g --out-dir C:\rs\rustlab\target\debug --
emit=dep-info,link -L dependency=C:\rs\rustlab\target\debug -L dependency=C:\rs\rustlab\target\debug\deps --extern libc=C:\rs\rustlab\ta
rget\debug\deps\liblibc-0c94fdfb80c4b805.rlib`
note: link against the following native artifacts when linking against this static library
note: the order and any duplication can be significant on some platforms, and so may need to be preserved
note: library: gcc_eh
note: library: gcc_eh
note: library: ws2_32
note: library: userenv
note: library: shell32
note: library: advapi32

例如,我有 WS2_32.lib 的三个 x86 版本。用的是哪一个?

C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86\WS2_32.Lib
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x86\WS2_32.Lib
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\um\x86\WS2_32.Lib

最佳答案

There are two ABI options for Rust on Windows : MSVC 和 GNU (GCC)。您说您使用的是 32 位版本的 Rust 1.6; Rust 1.6 没有使用 MSVC ABI 的 32 位版本(它仅从 Rust 1.8 开始可用),所以我假设您使用的是 GNU ABI 版本。

如果您确实在使用 GNU ABI 版本,那么您需要链接到 GNU ABI 静态库。这些库的名称类似于 libXXXX.a , 而不是 XXXX.lib用于 MSVC。

如果您没有名为 libws2_32.a 的文件在你系统的任何地方,然后你需要安装 MinGW,它是 GCC for Windows 的一个端口,它还包括最常用的 Windows DLL 的静态库。 MinGW 有多个活跃的“分支”:mingw-w64TDM-GCC拥有比原始版本更新的 GCC MinGW项目,似乎处于休眠状态。

Is there a way to get the full paths for the libraries that were used?

通常,您在链接时不指定完整路径。对于 GCC,您传递类似 -lws2_32 的选项链接器将为您找到库。如果链接器找不到它,您可以添加 -L <path>在链接器的静态库搜索路径中添加目录的选项。

Cargo 有一些关于如何编写 build script 的文档。当你运行 cargo build 时可以自动添加这些选项.

关于rust - 我可以获得 Rust 链接的原生工件的完整路径吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35324907/

相关文章:

intellij-idea - 导入Rust项目时出现IntelliJ错误

rust - 通过列表向后循环时在 'attempt to subtract with overflow' 出现 panic

iterator - Rust 实现合并排序迭代器

mysql - `?` 运算符只能在返回 `Result` 或 `Option` (或实现 `std::ops::Try` 的其他类型)的函数中使用

docker - 在 docker 中构建 rust 项目导致 Cargo 卡住下载依赖项

testing - 如何获取所有 cargo 测试的列表?

rust - 使用实现来自不同 crate 的特征的结构

regex - 使用 Rust 的正则表达式箱时如何转义转义的正则表达式字符?

struct - 更新具有私有(private)字段的 Rust 结构的公共(public)字段

ubuntu - 无法使用 apt 安装 rustc 版本 1.7.0