Homepage Wiki Forum Buy

C/C++ Development Environment installation

From GNUBLIN

Contents


To compile C and C++ programs for the Gnublin board you need a cross-compiler , because the architecture on the Gnublin (ARM) is different to the one on your PC (x86). The cross-compiler generates executable code for the Gnublin ouf of the sourcecode on your computer.

Installation

The installation is pretty easy. To install the C cross compiler just type teh following into your console:

user@dev-pc ~ $ sudo apt-get install gcc-arm-linux-gnueabi

And for the C++ compiler just:

user@dev-pc ~ $ sudo apt-get install g++-arm-linux-gnueabi

Now the cross-compiler is installed on your development computer!

compile Hello-World-Program

To compile the programs for the Gnublin we use the toolchain we installed before. you start the toolchain with arm-linux-gnueabi-gcc respectively arm-linux-gnueabi-g++

A simple Hello World program:

 #include <stdio.h> 
 
 int main(void)
 {
   printf("Hello World!\r\n");
   return 0;
 }

Compile the Hello World program on your pc:

user@dev-pc ~ $ arm-linux-gnueabi-gcc -o hello hello.c

Now copy the program into the RootFS of the Gnublin via SSH or directly on the SD-Card


Alternatively: ELDK Toolchain

To compile C and C++ programs for the Gnublin board you need a cross-compiler , because the architecture on the Gnublin (ARM) is different to the one on your PC (x86). The cross-compiler generates executable code for the Gnublin ouf of the sourcecode on your computer.

Most of these commands require root rights so nearly all commands are preceded by sudo. If you get an error, check your command line. You may have forgotten the "sudo". On distributions without sudo you must be root (su).


1st step: Download

Download the development environment http://gnublin.org/downloads/eldk-eglibc-i686-arm-toolchain-qte-5.2.1.tar.bz2

cd /tmp
wget http://gnublin.org/downloads/eldk-eglibc-i686-arm-toolchain-qte-5.2.1.tar.bz2

the file will be stored in the /tmp directory.

2nd step: extract archive

sudo tar xjf eldk-eglibc-i686-arm-toolchain-qte-5.2.1.tar.bz2 -C /

This command extracts the content of the archive eldk-eglibc-i686-arm-toolchain-qte-5.2.1.tar.bz2. The cross-compiler will be copied into the /opt/eldk-5.2.1/ directory.

3rd step: create script for the environment variables

To set the environment variables right, there must be created a script in /opt/eldk-5.2.1/set.sh , so your hostsystem can use the cross-compiler

sudo touch set.sh

with the following content:

P1=/opt/eldk-5.2.1/armv5te/sysroots/i686-eldk-linux/usr/bin/armv5te-linux-gnueabi/
P2=/opt/eldk-5.2.1/armv5te/sysroots/i686-eldk-linux/bin/armv5te-linux-gnueabi/
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
export PATH=$P1:$P2:$PATH

4th step: set the environment variables

Before the cross-compiler can be used, the environment variables has to be set. This is done by sourcing the just created script:

. /opt/eldk-5.2.1/set.sh

Please note, the script isn't executed, only sourced! You must type the command exactly in this order: dot, space, path!


You may want to expand the .bashrc in the directory /home/USERNAME/ with the script

cat set.sh >> ~/.bashrc

and reload it afterwards.

. ~/.bashrc

5th step: use the cross-compiler

The cross-compiler now can be used

arm-linux-gnueabi-gcc -v

Alternative: installing the toolchain under Arch Linux

Under Arch Linux the toolchain can be installed with Sourcery CodeBench - Lite Edition.

mkdir -p /tmp/arm_cross
cd /tmp/arm_cross
wget http://aur.archlinux.org/packages/ar/arm-none-linux-gnueabi/PKGBUILD
makepkg -si

It's more comfortable if you use the following wrapper tools: packer yaourt.

# if yaourt is available:
yaourt -S arm-none-linux-gnueabi
# if packer is available
packer -S arm-none-linux-gnueabi

compiling the Hello-World-program

The toolchain for the Linux-Kernel and the bootloader begins with armv5te-. The GCC e.g. reads as follows armv5te-gcc. To compile programs for the Linux you must use the toolchain, which starts with arm-linux-gnueabi-. For a simple 'Hello World!' program you only need:

 #include <stdio.h> 

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

Compiling Hello World on the PC:

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

The programm must be transferred into the RootFS of the Gnublin by SSH or SD-Card.

In other languages