what is cross compilation?

Cross compilation is a technique in which we compile source code on ( for example on Linux x86 desktop machine) with intent to run the compiled code on different machine( for example on arm based system or mobile platform ).

How to cross compile c/cpp source code for arm?

To compile c/cpp source code for ARM target on Linux desktop (Ex. x86 machine ) we need different gcc toolchain. On linux Desktop system we need to install gcc/g++ compiler for arm machine. Here we will study cross compilation on ubuntu 13.10 x86 Desktop machine.

(1) Install arm gcc toolchain.To install open linux terminal and run below command.

#sudo apt-get install gcc-4.7-arm-linux-gnueabi


#sudo apt-get install gcc-4.7-arm-linux-gnueabi

(2) save below code as hello.c


int main()
     printf("Hello world \n");
return 0;

(3) Compile the above code by arm gcc by below command.

arm-linux-gnueabi-gcc-4.7 hello.c -o hello

The above command will produce hello executable. this could be run on arm target.

(4) Run file command to know file type of hello.

file hello

output will show :

hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0x91a2f4dedb52356ad1cdfbc2c7fb20a7b20d9abb, not stripped

Related Contents to follow