Compiling a Linux Program for Arm Architecture - Running on a Host Os

Compiling a Linux program for ARM architecture - running on a host OS

For ARM-Linux application development the preferable choice is a Linux Host(x86) machine with a ARM toolchain installed in it. In Ubuntu Desktop machine you can use the following command to install ARM toolchain:

apt-get install gcc-arm-linux-gnueabi

After toolchain installation you can use the following command for cross compilation:

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

Using this toolchain you can cross-compile your C program using Standard C library without the need of startup code. Applications can be cross-compiled at your Host Linux(x86) platform and run on Target Linux(ARM) platform.

Windows version of ARM-Linux Toolchain is also available. You can get it from here.

Linaro Developers Wiki - an open organization focused on improving Linux on ARM, will be a good reference for your work.

Compiling my C++ code for ARM Architecture

You need more than just a switch, you need a cross-compiler. You can make your own, but probably the easiest way is :

  • Find the development tools for your board. It probably comes with a development kit that includes a cross-compilation toolchain

  • If you don't have these, you can try to install a precompiled cross-compilation like the ones provided freely by CodeSourcery

Then you have to make the location of your toolchain (look for something like arm-none-linux-gnueabi-gcc) available in your path.

Cross compiling simple project is then easy, just override the CC variable in your Makefile :

CROSS = arm-none-linux-gnueabi-
CC = $(CROSS)gcc
LD = $(CROSS)ld

Linux cross-compilation for ARM architecture

There are two approaches I've used for ARM/Linux tools. The easiest is to download a pre-built tool chain directly.

Pro: It just works and you can get on with the interesting part of your project

Con: You are stuck with whichever version of gcc/binutils/libc they picked

If the later matters to you, check out crosstool-ng. This project is a configuration tool similar to the Linux kernel configuration application. Set which versions of gcc, binutils, libc (GNU or uCLibc), threading, and Linux kernel to build and crosstool-ng does the rest (i.e. downloads the tar balls, configures the tools, and builds them).

Pro: You get exactly what you selected during the configuration

Con: You get exactly what you selected during the configuration

meaning you take on full responsibility for the choice of compiler/binutil/libc and their associated features/shortcomings/bugs. Also, as mentioned in the comments, there is some "pain" involved in selecting the versions of binutils, C library etc. as not all combinations necessarily work together or even build.

One hybrid approach might be to start with the pre-built tools and replace them later with a custom solution via crosstool-ng if necessary.

Update: The answer originally used the CodeSourcery tools as an example of a pre-built tool chain. The CodeSourcery tools for ARM were free to download from Mentor Graphics, but they are now called the Sourcery CodeBench and must be purchased from Mentor Graphics. Other options now include Linaro as well as distribution specific tools from Android, Ubuntu, and others.

How to crosscompile a hello world C program for ARM

Since you say you can use make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm uImage you should have arm gnueabi toolchain available at your disposal. It should be then as easy as calling it like

arm-linux-gnueabi-gcc -I../inc *.c

C++/QT/ARM Processors Cross-compiling/Programming


Q. Is it important to host and target computers have the same architecture, I mean both should be 32-bits (x86 or i586/i686) or both should be 64-bits (x86_64)?

No, you can any variation, although I have never seen 32 bit host and 64 bit target. The other combination should just work according to my knowledge.

Q. Is it important to use which version of GCC with Qtopia? another thing is which version of QT/Embedded should be used?

Yes, it is important. Do not mix old and new softwares because they will not fit nicely together.

Q. Do I have to use the old versions of QT/Embedded like Qtopia or I can use the newer versions like qt-everywhere-opensource-src-4.8.4?

No. In fact, do not use Qtopia the ancient, try to use a recent Qt release like Qt 5.2. The reason is simply the fact that is design flaws, and it gets no maintenance these days.

another problem is about kernel version: is it important Q. Is it important to host and target computers have the same kernel number (x.y.z)?

No, it is almost always different, actually. That is due to the fact that there are so many varieties of the Linux kernel out there, used by different distributions or distribution generators.

At last, I appreciate you to give a your general but practical guideline/tips to cross-compiling from x86 GCC to FreindlyARM platform.

If you want to build Qt on your own for your target, you will need to pay attention to the -platform and -xplatform options. The former defines your host platform, and the latter the embedded target platform.

Basically, you need to make qmake has proper support for your board in form of mkspecs files. If it does not, it is relatively easy to get one from scratch based on the existing ones.

When you build your software for the embedded board, you will need to use the -spec option in a qmake based project to select the right target.

I would also suggest to give some consideration to QtCreator as a newcomer where you can properly configure the "kits", and customize the deployment steps, etc. It has a lot of builtin cross-toolchain development support.

Does the the 'linux' version of arm gcc compiler support -cpu=cortex-m4?

The compiler for 32-bit ARM on Ubuntu is arm-linux-gnueabihf-gcc or arm-none-eabi-gcc, roughly according to whether you want to compile code to run on a Linux OS or on bare metal. Look for the packages gcc-arm-linux-gnueabihf or gcc-arm-none-eabi.

The aarch64 compilers only support 64-bit ARM.



Related Topics



Leave a reply



Submit