为arm-linux-gnueabi-gcc交叉编译libcurl [英] Cross compile libcurl for arm-linux-gnueabi-gcc
问题描述
我一直在尝试从ubuntu eclipse交叉编译用于arm-linux-gnueabi-gcc ++的libcurl 7.35.0。
我已在GCC ++链接器中包含-lcurl optons。当我尝试使用下面的代码在G ++编译器中编译代码时,一切进展顺利,并且构建后没有错误。
I have been trying to cross compile libcurl 7.35.0 from ubuntu eclipse for arm-linux-gnueabi-gcc++. I have included -lcurl optons in GCC++ linker. when I am trying to compile the code in G++ compiler for the below code everything is going well and no error was there after building.
#include <iostream>
#include <curl/curl.h>
using namespace std;
int main()
{
return
}
但是当我尝试使用arm-linux-gnueabi-gcc ++进行交叉编译但尝试构建时会产生编译错误:
But when I am trying to cross compile using arm-linux-gnueabi-gcc++ but trying to Build this produces compilation errors:
/ usr / include /curl/curlrules.h:143:41:错误:数组' curl_rule_01 '的大小为负
/usr/include/curl/curlrules.h:153:53:错误:大小数组' curl_rule_02 '的值为负
/usr/include/curl/curlrules.h:143:41: error: size of array ‘curl_rule_01’ is negative /usr/include/curl/curlrules.h:153:53: error: size of array ‘curl_rule_02’ is negative
请帮助我指导如何为ARM交叉编译libcurl。
Kindly help me to guide how to cross compile libcurl for ARM.
推荐答案
我还记得当初我不得不交叉编译curl的时候……那天!卷曲在做什么虽然很奇怪,但是却很聪明。
I remember back when I had to cross-compile curl... what a day! What curl is doing is fairly odd, but yet clever.
如果您看到那条线,就会看到以下内容:
if you look at that line you see this:
typedef char
__curl_rule_01__
[CurlchkszEQ(long, CURL_SIZEOF_LONG)];
如果您查看CurlchkszEQ,您将得到
and if you look at CurlchkszEQ, you get
#define CurlchkszEQ(t, s) sizeof(t) == s ? 1 : -1
因此,此例程强制 sizeof(long)= = CURL_SIZEOF_LONG
,如果不这样做,它将在该数组初始化程序中放置一个负数,并导致构建失败。
So this routine is enforcing that sizeof(long) == CURL_SIZEOF_LONG
, if it does not, it will put a negative number in that array initializer and cause the build to fail.
, CURL_SIZEOF_LONG
在 curlbuild.h
中定义,并定义为 8
...在x86_64机器上。也就是说,在 /usr/include/curl/curlbuild.h
中将其设置为 8
。不过,您并不关心x86_64!您正在为手臂编译... 32位体系结构,其中 sizeof(long)== 4
,而不是 8
和 CURL_SIZEOF_LONG
被错误地设置为 8
!因此,看来您的编译器正在使用系统级x86_64 curl头文件,该文件位于 / usr / include /...
,而不是交叉编译器的头! (例如,我的位于 / opt / cross / arm-unknown-linux-gnueabi / include /...
中,但您的不是)。
Here's the deal, CURL_SIZEOF_LONG
is defined in curlbuild.h
, and it is defined to 8
... on an x86_64 machine. That is, in /usr/include/curl/curlbuild.h
it is set to 8
. You don't care about x86_64 though! You're compiling for arm... a 32-bit architecture where sizeof(long) == 4
, not 8
and CURL_SIZEOF_LONG
is improperly set to 8
! So it appears your compiler is picking up on the system wide, x86_64 curl header files at /usr/include/...
rather than the headers for the cross compiler! (for example mine are in /opt/cross/arm-unknown-linux-gnueabi/include/...
, but yours probably are not).
因此,在编译编译器时, sizeof(long)== 4!= CURL_SIZEOF_LONG
会崩溃。理论上,解决问题的方法很简单,只需在编译器中更改配置即可使用交叉编译器包含的内容。在Eclipse中,我不确定该怎么做,尽管我确信这是可能的。
So when compiling the compiler resovles that sizeof(long) == 4 != CURL_SIZEOF_LONG
and properly crashes. The way to fix the problem is simple in theory, just change your configuration in your compiler to use the cross-compiler includes. In Eclipse, I am not sure how to do it, though I am sure it is possible.
您可能会发现,从终端创建curl会更容易,例如:
You might find it easier just to build curl from the terminal like so:
curl $ ./configure --host=arm-linux-gnueabi --prefix=/path/to/your/arm-linux-gnueabi/arm-linux-gnueabi
... configure stuff ...
curl $ make && make install
这篇关于为arm-linux-gnueabi-gcc交叉编译libcurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!