gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 08:00:35 28 4
gpt4 key购买 nike

我在 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com