将目标链接到库

时间:2015-06-23 06:27:00

标签: cmake mingw

我有一个“CMakified”版本的CryptoPP,我正在使用CMake-GUI创建一个MakeFile,ming-make可以处理,如下图所示。

enter image description here

“MakeFile”创建成功但当我执行mingw32-make.exe时,我在最后得到了以下错误。

Linking CXX executable cryptest.exe
CMakeFiles\cryptest.dir/objects.a(test.cpp.obj):test.cpp:(.text+0x8e82): undefined reference to `setsockopt@20'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x5cb): undefined reference to `socket@12'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x643): undefined reference to `closesocket@4'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x6f0): undefined reference to `htonl@4'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x70a): undefined reference to `inet_addr@4'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x759): undefined reference to `htons@4'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x7f4): undefined reference to `bind@12'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x85b): undefined reference to `listen@8'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x909): undefined reference to `inet_addr@4'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x922): undefined reference to `gethostbyname@4'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x978): undefined reference to `htons@4'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xa18): undefined reference to `connect@12'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xaac): undefined reference to `accept@12'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xb58): undefined reference to `getsockname@12'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xbc6): undefined reference to `getpeername@12'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xc87): undefined reference to `send@16'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xd83): undefined reference to `recv@16'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xe25): undefined reference to `shutdown@8'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xe96): undefined reference to `ioctlsocket@12'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xfbb): undefined reference to `select@20'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1010): undefined reference to `select@20'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x11a1): undefined reference to `select@20'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x11f6): undefined reference to `select@20'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x133f): undefined reference to `getservbyname@8'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1407): undefined reference to `ntohs@4'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1526): undefined reference to `WSAStartup@8'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x16cf): undefined reference to `WSACleanup@0'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x17fb): undefined reference to `WSAGetLastError@0'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x180f): undefined reference to `WSASetLastError@4'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1cfc): undefined reference to `WSARecv@28'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1d27): undefined reference to `WSAGetLastError@0'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1f61): undefined reference to `WSAGetOverlappedResult@20'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1f8c): undefined reference to `WSAGetLastError@0'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x2397): undefined reference to `WSASend@28'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x23c1): undefined reference to `WSAGetLastError@0'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x24cc): undefined reference to `WSAEventSelect@12'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x2587): undefined reference to `WSAEnumNetworkEvents@12'
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x2a01): undefined reference to `WSAGetOverlappedResult@20'
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [cryptest.exe] Error 1
mingw32-make[1]: *** [CMakeFiles/cryptest.dir/all] Error 2
mingw32-make: *** [all] Error 2

我尝试将LDLIBS += -lws2_32添加到make文件的最后但这没有帮助。我想这些错误是因为make文件中没有提到目标链接库,但我不知道如何做到这一点。

2 个答案:

答案 0 :(得分:2)

CMakeLists.txt应致电

$(document).ready()

在命令target_link_libraries(cryptopp ws2_32) 之后解析未定义的引用。

答案 1 :(得分:0)

在遵循Kieth的上述评论之后,我发现LIBS和LDLIBS都没有得到CMAKE的尊重。要使用的变量是CXX_STANDARD_LIBRARIES。我在CMAKE Advanced选项中做了以下更改:

enter image description here


我在最后添加了-lws2_32,然后生成了“MakeFile” 这解决了这个问题。