2011-03-30 34 views
6
[[email protected] ~]$ g++ client.cpp -lcurl -o client.exe 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x23): undefined reference to `_imp__curl_global_init' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x5f): undefined reference to `_imp__curl_formadd' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x9b): undefined reference to `_imp__curl_formadd' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xa2): undefined reference to `_imp__curl_easy_init' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xc8): undefined reference to `_imp__curl_easy_setopt' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xe4): undefined reference to `_imp__curl_easy_setopt' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xf1): undefined reference to `_imp__curl_easy_perform' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x101): undefined reference to `_imp__curl_easy_cleanup' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x10e): undefined reference to `_imp__curl_formfree' 
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x11b): undefined reference to `_imp__curl_slist_free_all' 
collect2: ld returned 1 exit status 

我沒有在Linux上這個問題,所以我不知道爲什麼發生這種情況的窗口。我已經搜索了它,沒有發現任何東西,除了郵件列表存檔與相同的問題,並回復說「谷歌它」。如何解決這些libcurl鏈接錯誤?

我使用MinGW的。當我構建libcurl時,我確實收到了一些鏈接器警告,但他們似乎是ssl相關的,我不知道這是否是一個大問題,因爲它沒有錯誤。

*** Warning: linker path does not have real file for library -lssl. 
*** I have the capability to make that library automatically link in when 
*** you link to this library. But I can only do this if you have a 
*** shared version of the library, which you do not appear to have 
*** because I did check the linker path looking for a file starting 
*** with libssl and none of the candidates passed a file format test 
*** using a file magic. Last file checked: /ssl/lib/libssl.a 

*** Warning: linker path does not have real file for library -lcrypto. 
*** I have the capability to make that library automatically link in when 
*** you link to this library. But I can only do this if you have a 
*** shared version of the library, which you do not appear to have 
*** because I did check the linker path looking for a file starting 
*** with libcrypto and none of the candidates passed a file format test 
*** using a file magic. Last file checked: /ssl/lib/libcrypto.a 

*** Warning: linker path does not have real file for library -lz. 
*** I have the capability to make that library automatically link in when 
*** you link to this library. But I can only do this if you have a 
*** shared version of the library, which you do not appear to have 
*** because I did check the linker path looking for a file starting 
*** with libz and none of the candidates passed a file format test 
*** using a file magic. Last file checked: /mingw/lib//libz.a 
*** The inter-library dependencies that have been dropped here will be 
*** automatically added whenever a program is linked with this library 
*** or is declared to -dlopen it. 

*** Since this library must not contain undefined symbols, 
*** because either the platform does not support them or 
*** it was explicitly requested with -no-undefined, 
*** libtool will only create a static version of it. 

回答

6

Libtool只構建一個靜態libcurl而不是動態庫。你的頭文件正在尋找一個動態的libcurl。它可能不是libcurl中的錯,因爲我可以在支持的頭看到代碼__declspec(dllimport)__declspec(dllexport)(這是一個好兆頭包的作者知道什麼是什麼

技術細節:。see this answer regarding libssh

解決方案:-DCURL_STATICLIB編譯。

+0

嗯。我認爲libcurl建立了靜態和動態。 我試過-DCURL_STATICLIB,但現在我得到數百個鏈接器錯誤,說未定義引用WSAStartup @ 8,_imp__ares_library_init,ntohs @ 4,getsockopt @ 20等。 – VVV 2011-03-30 10:37:09

+0

http://www.nomorepasting.com/getpaste.php?pasteid= 36044 – VVV 2011-03-30 10:47:50

+1

您不鏈接任何相關的庫。你需要(至少)-lwinsock2'加上其他庫的'-l'標誌(它看起來像OpenSSL,可能還有其他一兩個)。 – 2011-03-30 23:10:36

7

我能夠通過添加選項-lcurl.dll避免這些捲曲在Windows上鍊接(MinGW的win32)中的錯誤。-DCURL_STATICLIB並不需要我的情況。

我的構建有兩個在MinGW的/ lib文件夾中的libcurl文件:libcurl.a and libcurl.dll.a

+1

感謝解決我的問題的breadcrumb g ++:Code :: Blocks> Settings> Compiler> Linker settings> Add> lib \ libcurldll.a && lib \ libcurl.a – 2015-11-17 12:21:12

1

使用的NetBeans 7.1 MinGW的有同樣的問題。從屬性,鏈接器添加庫libcurl.dll.a解決了我的問題。

此文件是下捲曲7.28.1 \ lib.libs位於後我跑了MinGW的化妝。

0

我有類似的錯誤(與libz進行和libsqlite)在不同的項目。 它由GNU libtool腳本生成。

在我的情況的原因是缺乏對這些庫的一些文件中(.la?)也許libz.dll.a庫的變體。

要擁有的automake/autoconf的構建./configure --prefix=... ; make所有必要的文件,你就必須建立zlibcryptosslconfiguremake按相同的MSYS。 cmake或自定義makefile構建通常不會作爲共享庫自動構建的依賴項。

另外,最簡單的選擇是建立動態捲曲通過CMake(https://github.com/bagder/curl.git