Cross compiled C Windows libcurl not correctly linked to Ubuntu

I'm currently trying to cross compile libcurl in c for Windows 32x on Ubuntu 64x 14.04. After a little research, I followed these steps:

1) Download the library from https://curl.haxx.se/download.html

2) Go to the extracted libcurl folder and do:

./configure --host=i686-w64-mingw32 --build=i686-pc-linux-gnu --prefix=/usr/i686-w64-mingw32/ --enable-static --disable-shared

3) Run: make

4) Run: sudo make install

Then I added these include statements:

 #include <winsock2.h> // Needed for curl #include <windows.h> // Windows API #include <curl/curl.h> int main(int argc, char** argv) { CURL *curl; CURLcode response; char url[] = "someurl.com"; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, url); //set url options /* Perform the request, res will get the return code */ response = curl_easy_perform(curl); if(response != CURLE_OK) { //Do something } /* always cleanup */ curl_easy_cleanup(curl); } return 0; } 

Now I tried to compile my code with the following arguments:

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

The compiler returned the following error code:

 /tmp/ccebLf6U.o:main.c:(.text+0x336): Not defined reference to `_imp__curl_easy_init' /tmp/ccebLf6U.o:main.c:(.text+0x365): Not defined reference to `_imp__curl_easy_setopt' /tmp/ccebLf6U.o:main.c:(.text+0x372): Not defined reference to `_imp__curl_easy_perform' /tmp/ccebLf6U.o:main.c:(.text+0x3f4): Not defined reference to `_imp__curl_easy_cleanup' collect2: error: ld returned 1 exit status 

Does anyone know how to fix this?

[EDIT]

Something really interesting, I came across the fact that if you call curl-config, you get a bunch of compiler options.

+7
c linux ubuntu libcurl cross-compiling
source share
3 answers

So, my solution to this problem is probably right here: Cross-compiling tips for libraries

Here are some tips and tricks for the mingw32 cross compilation compiler and curl compilation with my missing argument -DCURL_STATICLIB. I did not test this because I solved the problem without curls.

0
source share

Cross-compilation library Using --prefix , you define the top-level installation directory.

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

Same as for the files that they will be hosted /usr/i686-w64-mingw32/include

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

To indicate the correct location, you need to add -I/usr/i686-w64-mingw32/include to your command.

In the end, you compiled curl libs static only when you want to copy them: add -static to your command.

SO the correct command would be:

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

From frequently asked questions :

If you get a linker error, for example "unknown symbol __imp__curl_easy_init ..." you are associated with the wrong (static) library. If you want to use libcurl.dll and import lib, you do not need any additional CFLAGS, but use one of the import libraries below. These libraries are created by various lib / Makefiles. *:

  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 setting the linker -lcurl_imp or -llibcurl_imp

Refresh . Here are the write flags on my Ubuntu using MinGW64:

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

Why am I using libcurl_imp.lib instead of libcurldll.a as described in the table above? Becouse I am building curl with cmake that do libcurl_imp.lib . Therefore, you should check the name of the built-in library.

+1
source share

All Articles