FlyZhy.Org logo Projects - Cross Compiler

Before
HowTo
Example
Host Environment
Preparing
Doing
Hello World
After

It's the first important step for the development of Embedded System to make a well used cross compiler, this will tell you what's the structure of making cross compiler and how to make it with cross-2.95.3 for ARM as an example.

Before

HowTo

The structure for making cross compiler is:

binutils ---> Host ---> binutils (ld, as, etc.)
 source        gcc
                        Linux Kernel  glibc
                           source     source
                              |___+___|
                                       |
                                       |
 gcc   ---> Host ---> BootStrap ---> glibc
 source      gcc          Compiler              |
   |                                                           |
   +----------------------------------+---> Host ---> Full
                                                                            gcc      Compiler

top

Example

Host Environment

If you want to do following this document, the first important thing you should know is the host compiling environment for doing all of the following things.

Preparing

Organization

I would like to have everything well organized, therefore, the first to be prepared is the structure of the files and directories:

/arm ----- tars ------------ SourceDir
            | |
            | |
            | |--- BuildDir
            | |
            | +--- compressed source files (.gz)
            |
            +--- armtools

where

Download

These are files I need to compile cross-2.95.3 with the version and the address to download.

Remember to put all these files to /arm/tars/ direcory.

#ls /arm/tars/
BuildDir/
SourceDir/
binutils-2.11.tar.gz
gcc-2.95.3.tar.gz
gcc-2.95.3.patch
gcc-com.patch
glibc-2.2.3.tar.gz
glibc-linuxthreads-2.2.3.tar.gz
linux-2.4.18.tar.gz
patch-2.4.18-rmk7.gz

Doing

The exactly steps for this example.

Linux Kernel source

binutils

Compiling and installing binutils.

#cd /arm/tars/SourceDir/
#tar xvfz /arm/tars/binutils-2.11.tar.gz
#cd /arm/tars/BuildDir/
#mkdir binutils
#cd binutils
#/arm/tars/SourceDir/binutils-2.11/configure --target=arm-linux --prefix=/arm/armtools
#make all install

BootStrap Compiler

Compiling and installing c compiler for arm. Or you can directly download and use the gcc-core packages to omitting this step.

#cd /arm/tars/SourceDir
#tar xvfz /arm/tars/gcc-2.95.3.tar.gz

glibc

Compiling and installing glibc.

#cd /arm/tars/SourceDir/
#tar xvfz /arm/tars/glibc-2.2.3.tar.gz
#cd glibc-2.2.3/
#tar xvfz /arm/tars/glibc-linuxthreads-2.2.3.tar.gz
#cd /arm/tars/BuildDir
#mkdir glibc
#cd glibc/
#CC=arm-linux-gcc /arm/tars/SourceDir/glibc-2.2.3/configure --host=arm-linux --prefix=/arm/armtools/arm-linux --enable-add-ons --with-headers=/arm/armtools/arm-linux/include
#make

Before you run make install you must change a file in /arm/tars/SourceDir/glibc-2.2.3/manual directory named stdio.texi, or you will get an error. The solution is to substitute the word @ref{, , , with @ref{Top, , , at the 3268 and 3269 line. Then

#make install

Full Compiler

Using the original t-linux file to do this.

#cd /arm/tars/BuildDir
#mkdir gcc
#cd gcc/
#cp /arm/tars/SourceDir/gcc-2.95.3/gcc/config/arm/t-linux-orig /arm/tars/SourceDir/gcc-2.95.3/gcc/config/arm/t-linux
#/arm/tars/SourceDir/gcc-2.95.3/configure --target=arm-linux --prefix=/arm/armtools --enable-languages=c,c++ --with-local-prefix=/arm/armtools/arm-linux
#make all install

Hello World

Testing the cross-compiler just made.

/*
 * helloworld.c
 */

#include <stdio.h>

int main(void)
{
   printf("Hello, World!\n");
   return 0;
}

Then4

#arm-linux-gcc -o helloword helloworld.c
#file helloworld
helloworld: ELF 32-bit LSB executable, ARM, version 1 (ARM), dynamically linked (uses shared libs), not stripped

top

After

If you get some errors while doing something, just make yourself lucky because you can learn more than others. :)

top


1. Choose the appropriate kernel options according to your requirements. After this step you can just check whether you have include/linux/version.h and include/linux/autoconf.h generated which are for compiling glibc.

2. This step is necessary for compiling glibc, or else you will have some errors while compiling glibc.

3. If you donot do this modify you will get some errors.

4. Make sure that /arm/armtools/bin is in your PATH.