How do I solve these libcurl linking errors?

16,507

Solution 1

I was able to avoid these curl linking errors on windows (mingw win32) by adding option -lcurl.dll. -DCURL_STATICLIB was not needed in my case.

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

Solution 2

Libtool only built a static libcurl and not a dynamic library. Your headers are looking for a dynamic libcurl. It's probably not libcurl's fault, because I can see code in the headers that supports __declspec(dllimport) and __declspec(dllexport) (that's a good sign the package author knows what's what.

Technical details: see this answer regarding libssh.

Solution: Compile with -DCURL_STATICLIB.

Solution 3

Was having the same issue using netbeans 7.1 with mingw. From properties, linker adding library libcurl.dll.a solved the issue for me.

This file was located under curl-7.28.1\lib.libs after I ran the mingw make.

Share:
16,507

Related videos on Youtube

VVV
Author by

VVV

Updated on June 04, 2022

Comments

  • VVV
    VVV almost 2 years
    [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 happens on windows. I googled it already and didn't find anything except mailing list archives with the same question and reply saying "google it".

    I'm using mingw. I did get some linker warnings when I built libcurl but they seemed to be ssl related and I don't know if it's a big deal because it 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.
    
  • VVV
    VVV about 13 years
    Hm. I thought libcurl built both static and dynamic. I tried -DCURL_STATICLIB but now I get hundreds of linker errors say undefined reference to WSAStartup@8, _imp__ares_library_init, ntohs@4, getsockopt@20 etc.
  • Jack Kelly
    Jack Kelly about 13 years
    You're not linking in any of the dependent libraries. You'll need (at least) -lwinsock2` plus whatever the -l flags are for the other libraries (it looks like OpenSSL and possibly one or two others).
  • Alexx Roche
    Alexx Roche over 8 years
    Thanks for the breadcrumb that solves my problem g++: Code::Blocks > Settings > Compiler > Linker settings > Add > lib\libcurldll.a && lib\libcurl.a

Related