我有一个问题迫使CMake使用MSVS链接器而不是MinGW 连接。为了支持MSYS中的MSVC,我实现了一个强制CMake的bash脚本 使用MSVC编译器创建NMake文件:
cmake -G“NMake Makefiles”-DMSVC = true -DCOMPILER_ROOT = $ COMPILER_ROOT -DCMAKE_PROFILE = $ CMAKE_PROFILE -DCMAKE_BUILD_TYPE = $ CMAKE_DEBUG -DCMAKE_CXX_LINKER = $ COMPILER_ROOT / bin / 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_LINK来获得正确的依赖关系。但现在我又失败了:
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
有谁知道我做错了什么? 谢谢你的帮助。
祝你好运, 地狱犬
答案 0 :(得分:0)
这听起来像PATH问题中的经典“同名不止一件事”,其中“错误的”首先出现在PATH中。
如果你把MS工具的目录放在PATH的前面,你还会遇到同样的问题吗?
如果在MSYS bash提示符下键入“which link”,环境中的文件首先是什么文件?
Microsoft的工具可能不具备针对PATH中具有相同名称的其他工具的强大功能。 (即 - 也许mt.exe只是调用“link.exe”并期望它在PATH中,并没有完全限定它以确保它需要的link.exe ...)同样适用于MSYS工具。< / p>
当您在一台计算机上安装了多个开发环境时,您必须仔细设置构建环境以避免此类问题。