07-26-2023, 05:07 PM
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
<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>
<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>