Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!\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
like image 887
eactor Avatar asked Jun 05 '13 08:06

eactor


People also ask

Can I compile for x86 with arm?

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.

How do you cross-compile arms with gcc?

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'.


1 Answers

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

like image 56
eactor Avatar answered Sep 22 '22 06:09

eactor