我在 Windows 7 64 位上使用 CMake (2.8.11.2) 为 openmpi 1.4.3 包配置并生成了 nmake 构建文件。我正在使用“VS2012 x64 Cross Tools 命令提示符”。不幸的是,第一个 DLL 目标的链接步骤失败了,因为一些 traget 库以“/l”前缀添加到链接命令行,这会导致链接器发出警告,但随后会导致无法解析的外部符号,因为所需的库有被忽略了。IE
Linking C shared library ..\liblibopen-pal.dll
cd C:\home\re04179\thirdparty\openmpi-1.4.3-build\vc11\x64\release\opal
"C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -E vs_link_dll C:\PROGRA~2\MICROS~1.0\VC\bin\X86_AM~1\link.exe /nologo @CMakeFiles\libopen-pal.dir\objects1.rsp @C:\Users\RE04179\AppData\Local\Temp\nm1B31.tmp
Visual Studio Non-Incremental Link
LINK:
C:\PROGRA~2\MICROS~1.0\VC\bin\X86_AM~1\link.exe /nologo @CMakeFiles\libopen-pal.dir\objects1.rsp /out:..\liblibopen-pal.dll /implib:..\liblibopen-pal.dll.a /pdb:C:\home\re04179\thirdparty\openmpi-1.4.3-build\vc11\x64\release\liblibopen-pal.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO -lWs2_32.lib -lshlwapi.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST
LINK : warning LNK4044: unrecognized option '/lWs2_32.lib'; ignored
LINK : warning LNK4044: unrecognized option '/lshlwapi.lib'; ignored
Creating library ..\liblibopen-pal.dll.a and object ..\liblibopen-pal.dll.exp
win32.obj : error LNK2019: unresolved external symbol __imp_WSAGetLastError referenced in function win32_insert
evutil.obj : error LNK2001: unresolved external symbol __imp_WSAGetLastError
if.obj : error LNK2001: unresolved external symbol __imp_WSAGetLastError
win32.obj : error LNK2019: unresolved external symbol __imp_WSACloseEvent referenced in function win32_del
win32.obj : error LNK2019: unresolved external symbol __imp_WSACreateEvent referenced in function win32_recompute_event
win32.obj : error LNK2019: unresolved external symbol __imp_WSAEnumNetworkEvents referenced in function win32_socket_event_callback
win32.obj : error LNK2019: unresolved external symbol __imp_WSAEventSelect referenced in function win32_del
win32.obj : error LNK2019: unresolved external symbol __imp_WSAHtonl referenced in function win32_insert
等等
通过编辑文件 'C:\Program Files (x86)\CMake 2.8\share\cmake-2.8\Modules\Platform\Windows-MSVC.cmake' 的第 156 行
set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib")
至
set(CMAKE_C_STANDARD_LIBRARIES_INIT "ws2_32.lib shlwapi.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib")
即,显式添加所需的库,允许我成功构建包,但链接器警告仍然存在,这当然只是一种解决方法,但对问题没有令人满意的解决方案。