如何解决这些libcurl链接错误?
[[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.
Libtool只构建一个静态libcurl而不是动态库。你的头文件正在寻找一个动态的libcurl。它可能不是libcurl中的错,因为我可以在支持的头看到代码__declspec(dllimport)
和__declspec(dllexport)
(这是一个好兆头包的作者知道什么是什么
技术细节:。see this answer regarding libssh
解决方案:-DCURL_STATICLIB
编译。
我能够通过添加选项-lcurl.dll
避免这些卷曲在Windows上链接(MinGW的win32)中的错误。-DCURL_STATICLIB
并不需要我的情况。
我的构建有两个在MinGW的/ lib文件夹中的libcurl文件:libcurl.a and libcurl.dll.a
感谢解决我的问题的breadcrumb g ++:Code :: Blocks> Settings> Compiler> Linker settings> Add> lib \ libcurldll.a && lib \ libcurl.a – 2015-11-17 12:21:12
使用的NetBeans 7.1 MinGW的有同样的问题。从属性,链接器添加库libcurl.dll.a解决了我的问题。
此文件是下卷曲7.28.1 \ lib.libs位于后我跑了MinGW的化妆。
我有类似的错误(与libz进行和libsqlite)在不同的项目。 它由GNU libtool脚本生成。
在我的情况的原因是缺乏对这些库的一些文件中(.la?)也许libz.dll.a库的变体。
要拥有的automake/autoconf的构建./configure --prefix=... ; make
所有必要的文件,你就必须建立zlib
,crypto
和ssl
与configure
和make
按相同的MSYS。 cmake或自定义makefile构建通常不会作为共享库自动构建的依赖项。
另外,最简单的选择是建立动态卷曲通过CMake(https://github.com/bagder/curl.git)
嗯。我认为libcurl建立了静态和动态。 我试过-DCURL_STATICLIB,但现在我得到数百个链接器错误,说未定义引用WSAStartup @ 8,_imp__ares_library_init,ntohs @ 4,getsockopt @ 20等。 – VVV 2011-03-30 10:37:09
http://www.nomorepasting.com/getpaste.php?pasteid= 36044 – VVV 2011-03-30 10:47:50
您不链接任何相关的库。你需要(至少)-lwinsock2'加上其他库的'-l'标志(它看起来像OpenSSL,可能还有其他一两个)。 – 2011-03-30 23:10:36