How to solve these libcurl link errors?

[ 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 

I don't have this problem on linux, so I don't know why this is happening on Windows. I already figured it out on Google and found nothing but mailing list archives, with the same question and answer saying "google it".

I am using mingw. I got some linker warnings when I built libcurl, but they seemed to be related to ssl, and I don't know if this makes a big difference because it was built without errors.

 *** 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
c ++ windows curl linker mingw
source share
4 answers

I managed to avoid these twists associated with window errors (mingw win32) by adding the -lcurl.dll option. -DCURL_STATICLIB not needed in my case.

My build has two libcurl files in the mingw / lib folder: libcurl.a and libcurl.dll.a

+7
source share

Libtool only created a static libcurl, not a dynamic library. Your headers are looking for dynamic libcurl. This is probably not a libcurl error, because I see code in the headers that supports __declspec(dllimport) and __declspec(dllexport) (which is a good sign that the package author knows that.

Technical details: see this answer regarding libssh .

Decision. Compile with -DCURL_STATICLIB .

+6
source share

Had the same problem using netbeans 7.1 with mingw. Of the properties, the libcurl.dll.a library add library solved the problem for me.

This file was under curl-7.28.1 \ lib.libs after I started mingw make.

+1
source share

I had a similar error (with libz and libsqlite) in different projects. It is created by the GNU libtool script.

In my case, the reason was the lack of some files for these libraries (.la?) Or, possibly, libz.dll.a library options.

To have all the necessary files for automake / autoconf build ./configure --prefix=... ; make ./configure --prefix=... ; make , you will need to build zlib , crypto and ssl using configure and make under the same MSYS. cmake or custom makefile assemblies generally do not work as dependencies for autotool assemblies for shared libraries.

Another and easiest option is to build a dynamic curl with cmake ( https://github.com/bagder/curl.git )

0
source share

All Articles