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;
}
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
No. Its because cross compiler(including clang) can generate binaries from host gcc for a target. There is no compiler which can generate x86 instructions from arm.
Save this answer. Install gcc-arm-linux-gnueabi and binutils-arm-linux-gnueabi packages, and then just use arm-linux-gnueabi-gcc instead of gcc for compilation. This brings in the complete cross-compile environment, including binutils. On Ubuntu 13.10 you get gcc-4.7 for 'gnueabi' and gcc-4.8 for 'gnueabihf'.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With