我在Windows 10上使用32位版本的Rust 1.6来编译rustlab。当我运行cargo build
来构建它时,它会说
链接此静态库时链接以下本机工件
我想做到这一点。有没有办法获得所用库的完整路径?
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
例如,我有x86
个WS2_32.lib
个版本。使用了哪一个?
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
答案 0 :(得分:2)
There are two ABI options for Rust on Windows:MSVC和GNU(GCC)。你说你正在使用32位版本的Rust 1.6;没有使用MSVC ABI for Rust 1.6的32位版本(它只能从Rust 1.8开始使用),所以我假设您使用的是GNU ABI版本。
如果您确实使用的是GNU ABI版本,则需要链接GNU ABI静态库。对于MSVC,这些库的名称类似于libXXXX.a
,而不是XXXX.lib
。
如果您的系统上没有任何名为libws2_32.a
的文件,那么您需要安装MinGW,它是Windows的GCC端口,还包括最常用Windows的静态库DLL文件。有多个活跃的"分叉" MinGW:mingw-w64和TDM-GCC的GCC版本比最初的MinGW项目更新,后者似乎处于休眠状态。
有没有办法获得所用库的完整路径?
通常,您在链接时不指定完整路径。对于GCC,您传递一个类似-lws2_32
的选项,链接器将为您找到该库。如果链接器找不到它,您可以添加-L <path>
选项以在链接器的静态库搜索路径中添加目录。
Cargo有一些关于如何编写build script的文档,可以在您运行cargo build
时自动添加这些选项。