如何解决这些libcurl链接错误?

时间:2011-03-30 10:25:45

标签: c++ windows curl linker mingw

[Administrator@windows ~]$ 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上没有这个问题,所以我不知道为什么会在Windows上发生这种情况。我已经用谷歌搜索了,除了邮件列表档案以外,没有找到任何相同的问题和回复说“google it”。

我正在使用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.

4 个答案:

答案 0 :(得分:8)

我能够通过添加选项-lcurl.dll来避免这些卷曲链接Windows(mingw win32)上的错误。在我的案例中不需要-DCURL_STATICLIB

我的构建在mingw / lib文件夹中有两个libcurl文件:libcurl.a and libcurl.dll.a

答案 1 :(得分:6)

Libtool只构建了静态libcurl而不是动态库。您的标题正在寻找动态libcurl。这可能不是libcurl的错,因为我可以看到支持__declspec(dllimport)__declspec(dllexport)的标题中的代码(这是包装作者知道什么是好的标志。

技术细节:see this answer regarding libssh

解决方案:使用-DCURL_STATICLIB进行编译。

答案 2 :(得分:1)

使用netbeans 7.1和mingw有同样的问题。从属性中,链接器添加库libcurl.dll.a为我解决了这个问题。

运行mingw make后,此文件位于curl-7.28.1 \ lib.libs下。

答案 3 :(得分:0)

我在不同的项目中有类似的错误(使用libz和libsqlite)。 它由GNU libtool脚本生成。

我的理由是缺少这些库的某些文件(.la?)或libz.dll.a库的变体。

要获得automake / autoconf build ./configure --prefix=... ; make所需的所有文件,您必须使用zlib构建cryptosslconfiguremake在同一个MSYS下。 cmake或自定义makefile构建通常不能用作共享库autotool构建的依赖项。

另一个也是最简单的选择是使用cmake(https://github.com/bagder/curl.git)构建动态卷曲