ARM 交叉编译 helloworld [英] Cross Compile helloworld for ARM
问题描述
我正在为 ARM-CORTEX-A9 尝试一个简单的交叉编译 (cc):为了简单起见,这就是 c 代码:
I'm trying a simple cross compile (cc) for an ARM-CORTEX-A9: To keep things simple thats the c-code:
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
arm 上的本地编译工作正常,以 gcc helloworld.c -o helloworld
开始,而交叉编译以 arm-xilinx-linux-gnueabi-gcc helloworld 开始.c -o helloworld_cc
The native compilation on the arm works fine and is started with gcc helloworld.c -o helloworld
whereas the cross compile is started with arm-xilinx-linux-gnueabi-gcc helloworld.c -o helloworld_cc
GCC 版本:
nativ: gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) Target: arm-linux-gnueabihf
CC: gcc version 4.6.3 (Sourcery CodeBench Lite 2012.03-79) 目标:arm-xilinx-linux-gnueabi
readelf 的 ABI:
readelf-nativ:操作系统:Linux,ABI:2.6.31
readelf-cc:操作系统:Linux,ABI:2.6.16
readelf-nativ: OS: Linux, ABI: 2.6.31
readelf-cc: OS: Linux, ABI: 2.6.16
链接的库 - 交叉编译是静态链接的,所以它不应该错过任何库:
Linked libs - the cross compiled is statically linked so it shouldn't miss any libs:
root@localhost:/temp# ldd helloworld
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6ed8000)
/lib/ld-linux-armhf.so.3 (0xb6fce000)
root@localhost:/temp# ldd helloworld_cc
not a dynamic executable
问题:本地程序运行良好,cc总是以:
The Problem: the native program runs fine, the cc always ends up with:
root@localhost:/tmp# ./helloworld_cc
-bash: ./helloworld_cc: No such file or directory
任何提示,希望我已经包含了足够的信息.
Any hints, hopefully, I have included enough information.
编辑
将它静态链接就可以了,但现在文件的大小很大(678kB(CC-static)与 4kB(本机)?为什么即使它说它不是动态链接它也缺少库?类似的问题: 交叉编译静态C helloworld for Android 使用 arm-linux-gnueabi-gcc
Linking it static does the trick, but now the size of the file is huge (678kB (CC-static) vs. 4kB(native)? Why is it missing libs even if it says it is not dynamically linked? Similar question: Cross compiling static C hello world for Android using arm-linux-gnueabi-gcc
arm-xilinx-linux-gnueabi-gcc helloworld.c -o helloworld_cc -static
推荐答案
lib
文件夹 Linaro Ubuntu 中缺少一个链接.它出现在 readelf -a
Ther was a missing link in the lib
folder Linaro Ubuntu. It showed up with readelf -a
[Requesting program interpreter: /lib/ld-linux.so.3]
把lib/ld-linux.so.3
链接放到lib/arm-linux-gnueabihf/ld-2.15.so
它有效.
感谢谢尔盖的帮助
这篇关于ARM 交叉编译 helloworld的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!