2015-06-23 181 views
-1

我有一個「CMakified」版本的CryptoPP,我正在使用CMake-GUI創建一個MakeFile,它可以像下圖所示的那樣進行處理。

將目標鏈接到庫

enter image description here

的「生成文件」創建成功,但是當我執行mingw32-make.exe我在最後得到了下面的錯誤。

Linking CXX executable cryptest.exe 
CMakeFiles\cryptest.dir/objects.a(test.cpp.obj):test.cpp:(.text+0x8e82): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x5cb): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x643): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x6f0): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x70a): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x759): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x7f4): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x85b): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x909): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x922): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x978): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xa18): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xaac): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xb58): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xbc6): undefined reference to `getpe[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xc87): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xd83): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xe25): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xe96): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0xfbb): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1010): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x11a1): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x11f6): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x133f): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1407): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1526): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x16cf): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x17fb): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x180f): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1cfc): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1d27): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1f61): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x1f8c): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x2397): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x23c1): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x24cc): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x2587): undefined reference to `[email protected]' 
libcryptopp.a(socketft.cpp.obj):socketft.cpp:(.text+0x2a01): undefined reference to `[email protected]' 
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文件中提到,但我不知道如何做到這一點。

+0

在「連接CXX可執行文件cryptest.exe」和後面的「未解析的引用」消息之間,___應該是失敗的命令行的回顯;我猜CMake一定隱瞞了它 - _bad,bad,BAD_ CMake。 (如果這是默認的CMake行爲,那麼我認爲它是一個關鍵的CMake BUG)。看,沒有那個命令行,我們確實沒有任何診斷信息,以幫助我們確定問題。 –

+1

FWIW,用於指定庫的常規makefile變量是'LIBS',_not_'LDLIBS'。當然,CMake可能不會遵守這個約定 - 我不知道,因爲我不使用CMake。如果CMake _does_使用'LDLIBS',那是一個遞歸的擴展變量嗎?如果不是的話,那麼它需要___在____之前指定___在它曾經使用之前;在makefile結尾修改它可能沒有任何作用。 –

+0

你有寫過CMakeLists.txt還是加密++提供的? – Peter

回答

2

CMakeLists.txt應該叫

target_link_libraries(cryptopp ws2_32) 

命令ADD_LIBRARY後解決未定義的引用。

+0

Thankyou,我是Cmake新手,但我仍然喜歡傳統的做法:) – sjsam

0

在遵循Kieth的上述評論之後,我發現LIBS和LDLIBS都不被CMAKE所尊敬。要使用的變量是CXX_STANDARD_LIBRARIES。我的確在CMake的高級選項下面的變化:

enter image description here


我在最後添加-lws2_32然後產生 「Makefile」 文件。
這解決了這個問題。