我使用Windows 7 64位上的CMake(2.8.11.2)为openmpi 1.4.3软件包配置并生成了nmake构建文件。我正在使用“VS2012 x64交叉工具命令提示符”。不幸的是,第一个DLL目标的链接步骤失败,因为一些traget库被添加到带有'/ l'前缀的链接命令行,这会导致链接器发出警告,但结果是未解析的外部符号,因为所需的库有被忽略了。即。
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")
,即显式添加所需的库,允许我成功构建包,但链接器警告仍然存在,这当然只是一种解决办法,但没有令人满意的解决方案。
答案 0 :(得分:0)
您应该将库添加到openmpi
cmake文件中,而不是更改CMake文件。并且您永远不应该更改CMake分发文件,而是修复您正在尝试构建的库附带的文件。大多数时候它是图书馆的bug而不是CMake的。