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)
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.
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:
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.
A summery of the installation. Click to confirm the summary and start installation. It may take for a while.
When the installation finishes, you will see
When the installation finishes, at the windows command mode you will see files have been installed at C:\CodeSourcery.
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.
(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
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!
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://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