交叉编译 helloworld for ARM [英] Cross Compile helloworld for ARM

查看:25
本文介绍了交叉编译 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!
");
   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 版本 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 目标:arm-linux-gnueabihf

CC:gcc 版本 4.6.3(Sourcery CodeBench Lite 2012.03-79)目标:arm-xilinx-linux-gnueabi

来自 readelf 的 ABI:

readelf-nativ:操作系统:Linux,ABI:2.6.31readelf-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)vs.4kB(native)?为什么即使它说它不是动态链接的,它也缺少库?类似的问题: 交叉编译静态 C hello使用 arm-linux-gnueabi-gcc 的 Android 世界

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

它有效.

感谢谢尔盖的帮助

这篇关于交叉编译 helloworld for ARM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆