Search code examples
c++curl

cURL specific undefined reference


I finally was able to link cURL correctly (I think) to Code Blocks (GNU compiler) and get all the dll issues sorted. It was able to compile and run correctly once, then stopped working with new errors associated with libcurl.a(url.o). The two errors are

undefined reference to 'idna_to_ascii_lz' 
undefined reference to 'string_prep_locale_charset'.  

The errors came up after a previously successful build, which doesn't make sense to me, because of the minimal modifications I had made. My build options are -lcurl --lws2_32, and -lwsock32 (to get rid of another error that popped up after successful compile).

I think my linking is successful because of the previous successful builds, and I added all the dlls that it was previously asking for. How do I fix it, and why did it build fine before? Are there compiler settings I should turn on? The only one on is -Wall and -fexceptions

The test code is below and was taken directly from another website with few modifications.

#define CURL_STATICLIB
#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <string>
#include <iostream>

size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
    size_t written;
    written = fwrite(ptr, size, nmemb, stream);
    return written;
}

int main(void) {
    CURL *curl;
    FILE *fp;
    CURLcode res;
    std::cout << "Hello World";
    char *url = "http://cnn.com";
    char outfilename[FILENAME_MAX] = "C:\\bbb.txt";
    curl = curl_easy_init();
    if (curl) {
        fp = fopen(outfilename,"wb");
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        fclose(fp);
    }
    return 0;
}

Thanks for all your help

Update: Per TimRau's suggestion, I added the -lidn to linker options. I now get the following errors:

||=== Build: Debug in Curl2 (compiler: GNU GCC Compiler) ===|

C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ssluse.o)|| undefined reference to `ERR_remove_thread_state'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_err2stringA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_set_optionA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_simple_bind_sA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_search_sA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_err2stringA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_err2stringA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_set_optionA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_initA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_get_dnA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_first_attributeA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_get_values_lenA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_memfreeA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_next_attributeA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_memfreeA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_memfreeA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_memfreeA'|
||=== Build failed: 17 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

For link libraries, I have the following linked: c:\libs\libcurl_imp.lib c:\libs\libeay32.lib c:\libs\openldap.lib c:\libs\ssleay32.lib

I also have the curl lib in my linker search directories and curl include compiler search directories. I put them in according to the instructions found online at http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/ Because it built and worked once, I think these settings are correct but I am at the limits of my understanding this part of programming.

Update 2: GOt rid of first error by adding


Solution

  • You need to add -lidn -lwldap32 in the end of the compilation command.