Qub*_*asa 8 c linux ubuntu cross-compiling libcurl
我目前正在尝试在Ubuntu 64x 14.04上为Windows 32x交叉编译libcurl.经过一番研究后,我遵循了以下步骤:
1)从https://curl.haxx.se/download.html下载库
2)进入解压缩的libcurl文件夹并执行:
./configure --host=i686-w64-mingw32 --build=i686-pc-linux-gnu --prefix=/usr/i686-w64-mingw32/ --enable-static --disable-shared
3)执行:make
4)执行:sudo make install
然后我添加了这些包含语句:
#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;
}
Run Code Online (Sandbox Code Playgroud)
现在我尝试用以下参数编译我的代码:
i686-w64-mingw32-gcc main.c -o main.exe -L/usr/i686-w64-mingw32/lib -lcurl
Run Code Online (Sandbox Code Playgroud)
编译器返回以下错误代码:
/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
Run Code Online (Sandbox Code Playgroud)
有人知道如何解决这个问题吗?
[编辑]
我偶然发现的一件非常有趣的事情是,如果你调用curl-config,你会得到一堆编译器选项.
所以我对这个问题的解决方案可能就在这里: Crosscompiletipsforlibraries
这些是交叉编译器 mingw32 和使用我缺少的参数 -DCURL_STATICLIB 编译curl 的一些提示和技巧。不过我没有对此进行测试,因为我没有使用卷曲就解决了问题。