2016-02-10 47 views
3

我在Windows 10上使用32位版本的Rust 1.6來編譯rustlab。當我運行cargo build構建它,它針對以下本土文物我可以得到Rust鏈接的原生文物的完整路徑嗎?

鏈接反對這種靜態庫鏈接

時說,我想這樣做。有沒有辦法獲得使用的庫的完整路徑?

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 3個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 

回答

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靜態庫。這些庫的名稱爲libXXXX.a,而不是用於MSVC的XXXX.lib

如果您的系統上沒有任何地方存在名爲libws2_32.a的文件,那麼您需要安裝MinGW,它是Windows版GCC的一個端口,也包含最常用Windows DLL的靜態庫。 MinGW有多個活躍的「分支」:mingw-w64TDM-GCC擁有比原來的MinGW項目更新的GCC版本,該項目似乎處於休眠狀態。

有沒有一種方法可以獲得使用的庫的完整路徑?

通常,鏈接時不指定完整路徑。對於海灣合作委員會,你通過一個選項,如-lws2_32,鏈接器會爲你找到該庫。如果鏈接程序找不到它,則可以添加-L <path>選項以在鏈接程序的靜態庫的搜索路徑中添加一個目錄。

Cargo有一些關於如何編寫build script的文檔,可以在運行cargo build時自動添加這些選項。

+0

你猜對了。我正在使用Rust的GNU 32位版本來爲GNU Octave構建庫。我看到Rust有一個'libws2_32.a',Octave也有'libws2_32.a'。我如何知道它們是否兼容?我可以讓Rust使用Octave中的一個嗎?這些位置是'C:\ Program Files(x86)\ Rust stable GNU 1.6 \ lib \ rustlib \ i686-pc-windows-gnu \ lib \ libws2_32.a'和'C:\ Octave \ Octave-4.0.0 \ lib \ libws2_32.a'。如果我創建了一個將'rustc-link-search'輸出到Octave路徑的構建腳本,它會從那裏使用'libws2_32.a'嗎? –

+1

*我怎麼知道它們是否兼容?*嘗試它們兩個!說真的,我認爲他們都應該工作,只要他們定義你的應用程序及其依賴關係需要的符號。如果與Octave的'libws2_32.a'鏈接不起作用,您將無法鏈接Octave的其他庫! * ...它會使用'libws2_32.a'嗎?*我想是的。確保一種方法是使用[進程監視器](https://technet.microsoft.com/en-us/sysinternals/bb896645)來監視具有該名稱的文件上的事件。 –

相關問題