2. Hello world 2: Sourcery cross-Compiler (Win7) for ubuntu (BeagleBoard)

16 May 2012 12:20

(Part 1) Pre<     Return to: Embedded Code Generation Home    Next> (Part 3)

 

  1. Install Code Sourcery CodeBench Lite at Win7
  2. Build Hello world at Win7 and run it at Beagleboard
  3. What is arm-none-linux-gnueabi


These instructions show how to use the CodeSourcery GNU Toolchain at Windows 7 to compile C/C++ programs for the BeagleBoard-xM linux embedded system.

 

OE is a good toolchain, but it may be too big and the installation of it is too complicated for me. (I tried once, but failed.  I was confused by their various versions, branches and dependences. My brain has been damaged by the Microsoft Windows. As a newbie to OE and bitBake,  I prefer a simple installation by download the file, run it and get the installation done. The Linux people have treated people like me with kindness and pity.).

 

1. Install Sourcery_CodeBench_Lite_for_ARM_GNU_Linux at Windows 7


The following instructions are mainly gleaned from the Sourcery Getting Started document.

 

          (1a) Download. Download the Sourcery Lite version  from http://www.codesourcery.com/sgpp/lite/arm (Target: GNU/Linux). Please note the difference between EABI and GNU/Linux, see my note at the end.

Machine generated alternative text: Read thi
ARM processors DownIo
This release supports ARM, Thumb, and Downlo
Thumb-2 compilations for all architectures in
active use, including version 7 of the ARM
architecture. MIPS pi
This rele
Read the FAQ  for GNU
Download the EABI Release 
Download the GNUILinux Release  Read th
Download the uClinux Release  Downlo
Download the SymbianOS release  Downlo

 

          You may need register with your email to get the download link, where I was asked to provide my city. The download link is send to your email box. (One interesting thing is that, I put 'oxford' as my city. However, when I click the link in my email, it does not work. I have to used the oxford VPN to get it downloaded. It seems that they check your IP before you can start download.)

 

          You will see  IA32 GNU/Linux Installer and IA32 Windows Installer and packages (*.TAR). Down load the windows installer. It would be useful to have a look at the 'Getting Started Guide' document on that page and follow the instruction therein to complete the installation. 

 

Tips: (a) For Windows, the Sourcery G++ installer is provided as an executable with the .exe extension.

         (b) For GNU/Linux,  Sourcery G++ Lite is provided as an executable installer package with the .bin extension. You may also install from a compressed archive with the .tar.bz2 extension.

 

       (1b) Install  Double click the *.exe file to install. Following the instructions in Sourcery Getting Started document. Some key screen shots are:

 

Machine generated alternative text: f  Sourcery Codeßench Lite for ARM GNU/Linux
Sourcery CodeBench Lite for ARM GNUILinux Wizard
Welcome! lnstallAnywhere will guide you through the installation of Sourcery
Q Important Information CodeBench Lite forARM GNU/Linux.
Q Choose Install Set It is strongly recommended that you quit all programs before
Q Choose Install Folder continuing with this installation.
Q Addto PATH?
Clickthe Next button to proceed to the next screen. lfyouwantto
Q Choose Shortcut Folder change something on a previous screen, clickthe Previous button.
Q Pre-Installation Summary
Q Installing... You may cancel this installation at anytime by clicking the Cancel
Q Install Complete button.
Coo[SouRaRY
InstallAnywh ere
[ Cancel [ - EE EJ

Select the location where the CodeBench compilers (arm-none-linux-gnueabi-xxx) will be. 

I create a new folder CodeSourcery at C:\ and use the C:\CodeSourcery to install the CodeBench Lite.

Machine generated alternative text: * Sourcery CodeBench Lite for ARM GNU/Linux I =
Choose Install Folder
Welcome! Where Would You Like to Install?
J Important Information C:\CodeSourcery
J Choose Install Set [__Restore Default Folder__[[__Choose...__J
Choose Install Folder
Q Add to PATH?
Q Choose Shortcut Folder
Q Pre-lnstallation Summary
Q instarling
Q install L
(. (oSouwa
lnstallAnywhere
[__Cancel__[ [__Previous__] [ Next J

A summery of the installation. Click to confirm the summary and start installation. It may take for a while.

Machine generated alternative text: g Sourcery CocteBench Lite for ARM GNU/Linux = 
Pre-InstallaUon Summary
J Welcome! Please Rei’iew the Following Before Continuing:
J Important Information
J Choose Install Set Product Name:
J Choose Install Folder Sourcery CodeBench Lite for ARM GNU/Linux
J Add to PATH? Install Folder
J Choose Shortcut Folder C:\CodeSourcery
Pre-Installation Summary
Q Installing.. Shortcut Folder:
C.\ProgramData’iMicrosofl\Windows\Start Menu
Q Install Complete
Disk Space Information (for Installation
Target):
(OD[SOUR([RY Required 369.466.427 bytes
. Available 56.631.619.584 bytes
lnstallAnywhere
[ Cancel Previous Install

When the installation finishes, you will see

Machine generated alternative text: g Sourcery CocteBench Lite for ARM GNU/Linux = 
Install Complete
J Welcome! Congratulations! Sourcery CodeBench Lite forARM GNU/Linux
J Important Information has been successfully installed to:
J Choose Install Set
C:\CodeSourcery
Choose Install Folder
J Add to PATH? Press Doneto quitthe installer.
J Choose Shortcut Folder
J Pre-Installation Summary
J Installing...
Install Complete
( (oo[SouwaRY
lnstallAnywhere
Previous J Done

When the installation finishes, at the windows command mode you will see files have been installed at C:\CodeSourcery.

Machine generated alternative text: C:\Windows\system32\cmr1

The most important files are the executable files of cross compilers, which are at bin subfoler.

 

 Directory of c:\CodeSourcery\bin

23/10/2012  13:37    <DIR>          .

23/10/2012  13:37    <DIR>          ..

07/12/2011  09:56           380,928 arm-none-linux-gnueabi-abiactel.dll

07/12/2011  09:56           636,928 arm-none-linux-gnueabi-addr2line.exe

07/12/2011  17:56           659,456 arm-none-linux-gnueabi-ar.exe

07/12/2011  17:56         1,094,656 arm-none-linux-gnueabi-as.exe

07/12/2011  09:56           283,648 arm-none-linux-gnueabi-c++.exe

07/12/2011  09:56           634,880 arm-none-linux-gnueabi-c++filt.exe

07/12/2011  09:56           281,600 arm-none-linux-gnueabi-cpp.exe

07/12/2011  09:56            58,368 arm-none-linux-gnueabi-elfedit.exe

07/12/2011  09:56           283,648 arm-none-linux-gnueabi-g++.exe

07/12/2011  09:56           281,088 arm-none-linux-gnueabi-gcc-4.6.1.exe

07/12/2011  09:56           281,088 arm-none-linux-gnueabi-gcc.exe

07/12/2011  09:56            45,587 arm-none-linux-gnueabi-gcov.exe

07/12/2011  09:56         4,050,944 arm-none-linux-gnueabi-gdb.exe

07/12/2011  09:56           698,880 arm-none-linux-gnueabi-gprof.exe

07/12/2011  17:56         1,080,832 arm-none-linux-gnueabi-ld.exe

07/12/2011  17:56           645,120 arm-none-linux-gnueabi-nm.exe

07/12/2011  17:56           790,528 arm-none-linux-gnueabi-objcopy.exe

07/12/2011  17:56           950,784 arm-none-linux-gnueabi-objdump.exe

07/12/2011  17:56           659,968 arm-none-linux-gnueabi-ranlib.exe

07/12/2011  09:56           404,992 arm-none-linux-gnueabi-readelf.exe

07/12/2011  09:56           637,440 arm-none-linux-gnueabi-size.exe

07/12/2011  09:56           425,984 arm-none-linux-gnueabi-sprite.exe

07/12/2011  09:56           636,928 arm-none-linux-gnueabi-strings.exe

07/12/2011  17:56           790,528 arm-none-linux-gnueabi-strip.exe

07/12/2011  17:56           166,400 cs-make.exe

07/12/2011  17:56            39,424 cs-rm.exe

              26 File(s)     16,900,627 bytes

               2 Dir(s)  56,195,661,824 bytes free

c:\CodeSourcery\bin>

 

     (1c)Set and Check the environment variable PATH  After the installation completed, check your environment virables to make sure the PATH has been updated and include the Sourcery's \bin folder. For me, it is C:\CodeSourcery\bin

      Add it to the Win7's environment variatible PATH. By 'Start'->right click Computer-> Properties -> Advanced system Setings -> Advanced tab -> Environment Variable button -> select 'PATH' in 'User variable for xxx' box -> Edit. A new window pops out and check the string of 'Variable Value'.

 

You should see a string of 'C:\CodeSourcery\bin' at the beginning of the path variable (see the figure below). If unfortunately you do not see it, add 'C:\CodeSourcery\bin;' manually. Please note the ; at the end of 'C:\CodeSourcery\bin'.

 

Click OK to save the path variable.

 

Machine generated alternative text: C:\CodeSourcery\bin;C:\Program Files ...
%USERPROFILE%\AppData\Local\Temp
%USERPROFILE%\AppData\Local\Temp
Environment Variables
User variables for dan
Variable Value
Ci
C
EA
Path
TEMP
TMP
System variables
Variable
Path
PATH EX
PROCES
PROCES
[ New... ] [ Edit... ] [ Delete ]
I Edit User Variable
Variable name:
Path
�Variable value:
:\CodeSourcery\bin;C:\Program Files (x8
j OK ]] Cancel ]
I L il Cancel j

 

Machine generated alternative text: To set the PATH on a system fuming Microsoft Windows 7. from the desktop bring up the Start
menu and light click on Computer. Select Properties and click on Advanced system
settings. Go to the Advanced tab. then click on the Environment Variables button.
Select the PATH variable and click the Edit. Add the string ; C : \Program Fi les\Sourcery
G++\bin to the end. and click OK. Be sure to adjust the patimame to reflect your acrnal installation
directory.

 

     (1d) Verify the compiler:   You can test that your PATH is set up correctly by running the following command at windows cmd window:

 

> arm-none-linux-gnueabi-g++ -v

 

Machine generated alternative text: C:\Windows\system32\crr

Verify that the last line of the output contains: Sourcery CodeBench Lite 2011.09-70.

 

Assembler:

arm-none-linux-gnueabi-as.exe 

C compiler:

 arm-none-linux-gnueabi-gcc

C linker:

arm-none-linux-gnueabi-gcc

C++ linker:

arm-none-linux-gnueabi-g++

Archiver:

arm-none-linux-gnueabi-ar

Debugger:

arm-none-linux-gnueabi-gdb

 

 

 

2. Build Hello world at Win7 and run it at Beagleboard


 

Write a simple program (I copy the example from the Sourcery Getting Started document, )  to test the  arm-none-linux-gnueabi-g++ cross-compiler.

click here to download the program main.c


#include <stdio.h>

int factorial(int n) {

if (n == 0)

     return 1;

    return n * factorial (n - 1);

}

 

int main () {

    int i;

    int n;

    for (i = 0; i < 10; ++i) {

         n = factorial (i);

         printf ("factorial(%d) = %d\n", i, n);

    }

}


Type in the follwing command at Win7 command window to compile and link this program:

> arm-none-linux-gnueabi-gcc -o  factorial  main.c

 

If you are building a C++ application, instead of a C application, replace arm-none-linux-gnueabi-gcc with arm-none-linux-gnueabi-g++.
If the building process goes well, there should be no output string at the command window. As specified by the -o facotrial parameters, the executable output file of the main.c is factorial (without extension). You can use dir command to check if you have got a factorial file at your current folder.

 

Copy factonial to your Beagleboard (see Transfer files from Windows to Beagleboard over Ethernet , where I use WinSCP to transfer the executable file (e.g., a.out) to my home directory at Beagleboard.)

 

Login to the Beaglebard via remote terminatial. Go to your home directory, change the mode of the fractional to execuatbla.e

$ chmod 777 fractional

And run

$ ./factorial

 

You will get the output at your terminal. If you have reach here, well done. Congratulations!

Machine generated alternative text: COM6-PuUY __________
¿a
ubuntu@omap: � ubuntu
—bash: ubuntu: command not found
ubuntu@omap:-$ is
arm�011. 03-4l-arm-none-iinux-gnueabi.bin heiioworid Pictures
Desktop main2.c Pubiic
Documents main.c Tempiates
Downloads Music Videos
factoriai myTestModei_rtt
ubuntu@omap: —s . /factorial
factorial(O) = 1
factoriai(l) = 1
factoriai(2) = 2
factoriai(3) = 6
factoriai(4) = 24
factoriai(5) = 120
factoriai(6) = 720
factoriai(7) = 5040
factoriai(8) = 40320
factoriai(9) = 362880
ubuntu@omap:� LI

3. What is arm-none-linux-gnueabi?


A naming convention of the gcc cross-compiler

 

I found a good explanation of the gcc cross-compiler naming convention at

http://stackoverflow.com/a/5731708

given by Osgx and rubenvb

 

arm-none-eabi (e.g. CodeSourcery ARM compiler for bare-metal systems) is for building low-level applications such as Uboot and Linux Kernel image that don't have an underlying operating system.

 

arm-none-linux-gnueabi (CodeSourcery ARM compiler for linux) is for building Lunix applications such as user code that runs on an operating system, such as Ångström. I've used this successfully for both "Hello, world" and a simple X11 application.

 

arm-none-eabi-g++ for C

arm-none-eabi-gcc for C++

 

 

Someboday claims:

But for Beagle you  don't need this (arm-none-EABI).We build everything (U-Boot, Kernel and user space)  with arm-none-linux-gnueabi and this is fine. So you don't need

arm-none-eabi.

 

 

arm-elf is usually the prefix for GNU toolchains created for the arm-elf
target, arm-none-eabi for the target arm-eabi.

 <http://embdev.net/topic/129737>

 

I learnt from

<http://stackoverflow.com/questions/5731495/can-anyone-explain-the-gcc-cross-compiler-naming-convention>

 <http://hi.baidu.com/rwen2012/blog/item/538d34f0ceffbea9a50f52c6.html>

<https://groups.google.com/forum/?fromgroups#!topic/beagleboard/FBcq2K9vfW8>

 

Created with Microsoft OneNote 2010
One place for all your notes and information