Search code examples
linuxg++cross-compilinglibcurlmingw-w64

libcurl with x86-64-w64-mingw32-g++ undefined reference. g++ works fine


I am trying to cross-compile simple C++ program for Windows using libcurl and Linux. I am using the following code:

x86_64-w64-mingw32-g++ -DCURL_STATICLIB curl_example.cpp -o e -lcurl

However, I get the following error:

/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccNXyMyw.o:curl_example.cpp:(.text+0xa5): undefined reference to `curl_easy_setopt'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccNXyMyw.o:curl_example.cpp:(.text+0xbd): undefined reference to `curl_easy_setopt'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccNXyMyw.o:curl_example.cpp:(.text+0xc9): undefined reference to `curl_easy_perform'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccNXyMyw.o:curl_example.cpp:(.text+0xd8): undefined reference to `curl_easy_cleanup'
collect2: error: ld returned 1 exit status

I include curl like this: #include <curl/curl.h>

And I've tried every suggested solution to the problem I could find. Also I have to note, that if I use g++, it works fine:

g++ -DCURL_STATICLIB curl_example.cpp -o e -lcurl

What could be the issue?


Solution

  • I had to compile curl for the x86_64-w64-mingw32, as @KamilCuk suggested. In order to do that, I configured with

    ./configure --build x86_64-pc-linux-gnu --host x86_64-w64-mingw32 --prefix=/usr/x86_64-w64-mingw32