Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
831 views
in Technique[技术] by (71.8m points)

gcc - Cross Compile helloworld for ARM

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;
}

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 Version:

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) Target: arm-xilinx-linux-gnueabi

ABI from readelf:

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

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.

edit

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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]

Putting the link lib/ld-linux.so.3 to lib/arm-linux-gnueabihf/ld-2.15.so

and it works.

Thanks for the help Sergey


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...