Cross compiled C Windows libcurl doesn't get linked correctly on Ubuntu Cross compiled C Windows libcurl doesn't get linked correctly on Ubuntu linux linux

Cross compiled C Windows libcurl doesn't get linked correctly on Ubuntu


Cross-Compiling library Using --prefix you are defining the the toplevel installation directory.

Libs will be placed into /usr/i686-w64-mingw32/lib

Same thing for includes files they will be placed /usr/i686-w64-mingw32/include

Using -L/usr/i686-w64-mingw32/ you are pointing the wrong path for libraries and cross-compiler cannot find libcurl

To point to the correct include location you have to add -I/usr/i686-w64-mingw32/include to your command.

At the end you compiled curl libs static only then you want to compile them statically: add -static to your command.

SO the correct command will be:

i686-w64-mingw32-gcc -static -I/usr/i686-w64-mingw32/include -L/usr/i686-w64-mingw32/lib -lcurl main.c -o main.exe 


From the curls FAQ:

If you get linker error like "unknown symbol __imp__curl_easy_init ..." you have linked against the wrong (static) library. If you want to use the libcurl.dll and import lib, you don't need any extra CFLAGS, but use one of the import libraries below. These are the libraries produced by the various lib/Makefile.* files:

   Target:          static lib.   import lib for libcurl*.dll.   -----------------------------------------------------------   MingW:           libcurl.a     libcurldll.a   MSVC (release):  libcurl.lib   libcurl_imp.lib   MSVC (debug):    libcurld.lib  libcurld_imp.lib   Borland:         libcurl.lib   libcurl_imp.lib

Try path to linker -lcurl_imp or -llibcurl_imp

Update: Here is write flags on my Ubuntu with MinGW64:

i686-w64-mingw32-g++ -o app.exe objects.a -Lexternals/curl-7.39.0/lib -llibcurl_imp

Why I use libcurl_imp.lib instead libcurldll.a as described in table above? Becouse I build curl with cmake which make libcurl_imp.lib. So you should check name of built library.


So my solution to this problem probably lies right here:Cross compile tips for libraries

These are some tips and tricks for the cross compilation compiler mingw32 and the compilation of curl with my missing argument -DCURL_STATICLIB. I didn't test this out though because I solved the problem without curl.