Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 949 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cross compiled C Windows libcurl doesn't get linked correctly on Ubuntu

#1
I am currently trying to cross compile libcurl in c for Windows 32x on Ubuntu 64x 14.04. After a bit of research I followed these steps:

<p>1) Download library from

[To see links please register here]

</p>
<p>2) Go into extracted libcurl folder and execute:</p>
`./configure --host=i686-w64-mingw32 --build=i686-pc-linux-gnu --prefix=/usr/i686-w64-mingw32/ --enable-static --disable-shared`
<p>3) Execute: make </p>
4) Execute: 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 following arguments:

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

The compiler returned 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

Has someone an idea on how to fix this ?


**[EDIT]**
<p>Something really interesting I stumbled upon is that if you call curl-config you get a bunch of compiler options. </p>
Reply

#2
From the [curls FAQ][1]:

> 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.


[1]:

[To see links please register here]

Reply

#3
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
Reply

#4
So my solution to this problem probably lies right here:
[Cross compile tips for libraries][1]

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.


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through