简体   繁体   English

我可以获得Rust链接的本机工件的完整路径吗?

[英]Can I get the full path of native artifacts that Rust links against?

I'm using the 32-bit version of Rust 1.6 on Windows 10 to compile rustlab . 我在Windows 10上使用32位版本的Rust 1.6来编译rustlab When I run cargo build to build it, it says to 当我运行cargo build来构建它时,它说

link against the following native artifacts when linking against this static library 链接此静态库时链接以下本机工件

I would like to do exactly that. 我想这样做。 Is there a way to get the full paths for the libraries that were used? 有没有办法获得所使用的库的完整路径?

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

For example, I have three x86 versions of WS2_32.lib . 例如,我有三个x86版本的WS2_32.lib Which one was used? 使用了哪一个?

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 and GNU (GCC). 在Windows上有两个适用于Rust的ABI选项 :MSVC和GNU(GCC)。 You say you're using the 32-bit version of Rust 1.6; 你说你使用的是32位版本的Rust 1.6; there's no 32-bit version using the MSVC ABI for Rust 1.6 (it's only available starting with Rust 1.8), so I assume you're using the GNU ABI version. 没有使用MSVC ABI for Rust 1.6的32位版本(它只能从Rust 1.8开始使用),所以我假设你使用的是GNU ABI版本。

If you are indeed using the GNU ABI version, then you need to link against GNU ABI static libraries. 如果您确实使用的是GNU ABI版本,则需要链接GNU ABI静态库。 These libraries have names like libXXXX.a , instead of XXXX.lib for MSVC. 这些库的名称类似于libXXXX.a ,而不是用于MSVC的XXXX.lib

If you don't have a file named libws2_32.a anywhere on your system, then you need to install MinGW, which is a port of GCC for Windows that also includes static libraries for the most commonly used Windows DLLs. 如果您的系统上没有任何名为libws2_32.a的文件,则需要安装MinGW,这是一个用于Windows的GCC端口,它还包括最常用的Windows DLL的静态库。 There are multiple active "forks" of MinGW: mingw-w64 and TDM-GCC have more recent versions of GCC than the original MinGW project, which appears to be dormant. MinGW有多个活跃的“分支”: mingw-w64TDM- GCC比最初的MinGW项目有更新版本的GCC,这个项目似乎处于休眠状态。

Is there a way to get the full paths for the libraries that were used? 有没有办法获得所使用的库的完整路径?

Normally, you don't specify the full path when linking. 通常,链接时不指定完整路径。 For GCC, you pass an option like -lws2_32 and the linker will find the library for you. 对于GCC,您传递一个类似-lws2_32的选项,链接器将为您找到该库。 If the linker doesn't find it, you can add an -L <path> option to add a directory in the linker's search path for static libraries. 如果链接器找不到它,则可以添加-L <path>选项,以在链接器的静态库搜索路径中添加目录。

Cargo has some documentation on how to write a build script that can add these options automatically when you run cargo build . Cargo有一些关于如何编写构建脚本的文档,可以在运行cargo build时自动添加这些选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM