2011-11-17 29 views
4

我遇到了問題,強制CMake使用MSVS鏈接器而不是MinGW 鏈接器。爲了支持MSVC在MSYS我已經實現一個bash腳本迫使CMake的 使用MSVC編譯器創建NMAKE文件:如何使用MSYS在CMake中設置MSVC鏈接器

的cmake -G 「NMAKE Makefile文件」 -DMSVC =真-DCOMPILER_ROOT = $ COMPILER_ROOT -DCMAKE_PROFILE = $ CMAKE_PROFILE -DCMAKE_BUILD_TYPE = $ CMAKE_DEBUG -DCMAKE_CXX_LINKER = $ COMPILER_ROOT /斌/ linker.exe

CMake的正確使用MSVC編譯器和創建NMAKE文件作爲 預期:

$ sh build.sh -msvc /c/binrev/development/vs2010/VC -p 
removing CMakeCache.txt 
removing temporary directory CMakeFiles 
Create MSVC based NMake files. 
-- The C compiler identification is MSVC 
-- The CXX compiler identification is MSVC 
-- Check for CL compiler version 
-- Check for CL compiler version - 1600 
-- Check if this is a free VC compiler 
-- Check if this is a free VC compiler - no 
-- Check for working C compiler: c:/binrev/development/vs2010/VC/bin/cl.exe 
-- Check for working C compiler: c:/binrev/development/vs2010/VC/bin/cl.exe -- works 
-- Detecting C compiler ABI info 
-- Detecting C compiler ABI info - done 
-- Check for working CXX compiler: c:/binrev/development/vs2010/VC/bin/cl.exe 
-- Check for working CXX compiler: c:/binrev/development/vs2010/VC/bin/cl.exe -- works 
-- Detecting CXX compiler ABI info 
-- Detecting CXX compiler ABI info - done 
Execute: brCore.cmake 
Linker path CMAKE_CXX_LINKER: c:/binrev/development/vs2010/VC/bin/link.exe 

但是調用NMAKE時,CMake的仍使用MinGW的鏈接:

Linking CXX shared library bin\brCore.dll 
c:\binrev\development\mingw\bin\ld.exe: unrecognized option '-Wl,--enable-auto-import' 
c:\binrev\development\mingw\bin\ld.exe: use the --help option for usage information 
LINK failed. with 1 
NMAKE : fatal error U1077: "c:\binrev\development\cmake\bin\cmake.exe": Rückgabe-Code "0xffffffff" 
Stop. 
NMAKE : fatal error U1077: "c:\binrev\development\vs2010\VC\BIN\nmake.exe": Rückgabe-Code "0x2" 
Stop. 
NMAKE : fatal error U1077: "c:\binrev\development\vs2010\VC\BIN\nmake.exe": Rückgabe-Code "0x2" 
Stop. 

在CMakeCache調用的bash shell腳本後MinGW的連接設置,而不是MSVC鏈接:

//Path to a program. 
CMAKE_LINKER:FILEPATH=c:/binrev/development/mingw/bin/ld.exe 

好,我想通我必須設置CMAKE_LINKER變量而不是CMAKE_CXX_LINKER才能獲得正確的依賴關係。但現在我又一次失敗:

Linking CXX shared library bin\brCore.dll 
Das System kann die angegebene Datei nicht finden 
mt.exe : general error c10100b1: Failed to load file "bin\brCore.dll". Das System kann die angegebene Datei nicht finden. 
MT failed. with 31 

有沒有人知道我做錯了什麼? 感謝您的幫助。

最好的問候, 地獄犬

+1

您是否必須在MSYS shell中運行此版本?爲什麼不使用「Visual Studio命令提示符」作爲shell如果您使用MSVC編譯器並且無論如何nmake ...? – DLRdave

+0

我已經在MSYS shell中運行它,同時我也使用它作爲GCC。我會試用VS命令promt作爲shell。 – Hellhound

+0

我試圖通過從Visual Studio Command Promt執行cmake腳本來運行此操作,而不使用MSYS shell。同樣的效果,鏈接器試圖使用MinGW鏈接器... – Hellhound

回答

0

這聽起來像是在PATH問題的經典「一個物多用相同的名字」,與「錯」在一個路徑爲第一。

如果您將帶有MS工具的目錄放在PATH的前面,您是否仍然遇到同樣的問題?

如果您在MSYS bash提示符中鍵入「哪個鏈接」,那麼該環境中的第一個文件是什麼?

來自Microsoft的工具可能對PATH中具有相同名稱的其他工具不太健壯。 (即 - 也許mt.exe只是簡單地調用「link.exe」並期望它在PATH中,並沒有完全限定它以確保它需要link.exe)。對於MSYS工具也是類似的。

您確實必須仔細設置您的構建環境,以避免在單臺計算機上安裝多個開發環境時出現此類問題。