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

[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了,没有发现任何东西,除了邮件列表的档案与相同的问题,并回复说“谷歌它”。

我正在使用mingw。 当我构buildlibcurl时,我确实得到了一些链接器警告,但它们似乎是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)的头文件中看到代码(这是程序包作者知道是什么的好兆头。

技术细节: 请参阅关于libssh的这个答案 。

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

我能够通过添加选项-lcurl.dll来避免在窗口(mingw win32)上的这些curl链接错误。 在我的情况下不需要-DCURL_STATICLIB

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

使用netbeans 7.1与mingw有相同的问题。 从属性,链接器添加库libcurl.dll.a解决了我的问题。

这个文件位于curl-7.28.1 \ lib.libs之后,我运行了mingw make。

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

在我的情况下,原因是缺少这些库(.la?)的一些文件或库的libz.dll.a变种。

为automake / autoconf生成所有必需的文件./configure --prefix=... ; make ./configure --prefix=... ; make ,你将不得不建立zlibcryptossl configuremake在同一个MSYS下。 cmake或自定义的makefile版本通常不会作为shared-library autotool构建的依赖。

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