Difference between revisions of "BBB Cross Compiler"

From Klaus' wiki
Jump to: navigation, search
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
Neither the Fedora nor the Centos package system includes a suitable compiler for the ARMv7 processor.  
 
Neither the Fedora nor the Centos package system includes a suitable compiler for the ARMv7 processor.  
  
Luckily Linaro, does maintain a toolchain suitable for us. At [http://releases.linaro.org/components/toolchain/binaries this] point you can find the newest binaries for your operating system. Go up the directory structure to discover if a newer compiler has been released.
+
Luckily Linaro, does maintain a toolchain suitable for us. At [http://releases.linaro.org/components/toolchain/binaries this] point you can find the newest binaries for your operating system. At the end of the displayed list is a link to the '''newest''' versions. Click on the newest. Click on '''arm-linux-gnueabihf''' and in the next screen select ''gcc-linaro-n.m.x-20YY.MM-x86_64_arm-linux-gnueabihf.tar.xz'' where the letters match release number and date.  
  
The following is suited for [http://releases.linaro.org/14.11/components/toolchain/binaries/arm-linux-gnueabihf Fedora Linux] and probably other Linux'es as they are rather generic.
+
The following is suited for [http://releases.linaro.org/14.11/components/toolchain/binaries/arm-linux-gnueabihf Centos/Fedora Linux] and probably other Linux'es as they are rather generic.
  
For BBB running kernel version '''3.8.x''' use this:
 
 
<source lang=bash>
 
<source lang=bash>
 
]$ cd ~/Downloads
 
]$ cd ~/Downloads
]$ wget https://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/arm-linux-gnueabihf/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf.tar.xz
+
]$ wget https://releases.linaro.org/components/toolchain/binaries/V.v-20YY.MM/arm-linux-gnueabihf/gcc-linaro-n.m.x-20YY.MM-x86_64_arm-linux-gnueabihf.tar.xz
 
</source>  
 
</source>  
  
 
+
change the n, m, x, YY and MM with the current version. (NOTE: It seems as if the verion 6.2.something causes troubles.)
For BBB running kernel verison '''4.x''' use this:
+
<source lang=bash>
+
]$ cd ~/Downloads
+
]$ wget https://releases.linaro.org/components/toolchain/binaries/6.2-2016.11/arm-linux-gnueabihf/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf.tar.xz
+
</source>
+
 
+
which will download the newest version on the time of writing this.
+
  
 
I keep downloaded tools in the /opt directory rather than in the /usr/local or other places in the /usr tree.  
 
I keep downloaded tools in the /opt directory rather than in the /usr/local or other places in the /usr tree.  
Line 32: Line 24:
 
]$ mkdir toolchains
 
]$ mkdir toolchains
 
]$ cd toolchains
 
]$ cd toolchains
]$ tar Jxvf ~/Downloads/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf.tar.xz
+
]$ tar Jxvf ~/Downloads/gcc-linaro-n.m.x-20YY.MM-x86_64_arm-linux-gnueabihf.tar.xz
]$ ln -s gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/ gnueabihf
+
]$ ln -s gcc-linaro-n.m.x-20YY.MM-x86_64_arm-linux-gnueabihf/ gnueabihf
 
]$ file gnueabihf/bin/arm-linux-gnueabihf-gcc
 
]$ file gnueabihf/bin/arm-linux-gnueabihf-gcc
 
</source>
 
</source>

Revision as of 11:10, 12 November 2019

A few things are needed in order to set-up development of programs, that shall execute on an ARM platform. You'll need a cross compiler - a compiler that can generate ARM executable code while the compiler is executed on the PC platform, which is typically a Intel X86_64 architecture.

Cross Compiler

Neither the Fedora nor the Centos package system includes a suitable compiler for the ARMv7 processor.

Luckily Linaro, does maintain a toolchain suitable for us. At this point you can find the newest binaries for your operating system. At the end of the displayed list is a link to the newest versions. Click on the newest. Click on arm-linux-gnueabihf and in the next screen select gcc-linaro-n.m.x-20YY.MM-x86_64_arm-linux-gnueabihf.tar.xz where the letters match release number and date.

The following is suited for Centos/Fedora Linux and probably other Linux'es as they are rather generic.

]$ cd ~/Downloads
]$ wget https://releases.linaro.org/components/toolchain/binaries/V.v-20YY.MM/arm-linux-gnueabihf/gcc-linaro-n.m.x-20YY.MM-x86_64_arm-linux-gnueabihf.tar.xz

change the n, m, x, YY and MM with the current version. (NOTE: It seems as if the verion 6.2.something causes troubles.)

I keep downloaded tools in the /opt directory rather than in the /usr/local or other places in the /usr tree.

Notice: Use the correct version number below.

]$ cd /opt
]$ mkdir toolchains
]$ cd toolchains
]$ tar Jxvf ~/Downloads/gcc-linaro-n.m.x-20YY.MM-x86_64_arm-linux-gnueabihf.tar.xz
]$ ln -s gcc-linaro-n.m.x-20YY.MM-x86_64_arm-linux-gnueabihf/ gnueabihf
]$ file gnueabihf/bin/arm-linux-gnueabihf-gcc

These commands will create a toolchains directory in /opt and unpack the downloaded binaries into a structure. A symbolic link gnueabihf is created. This link can later be changed if a newer version of the compiler and libraries are downloaded.

The last command is just for ensuring that you've got the correct package downloaded. Expect something like this:

[klaus@klaus-x230 bin]$ file arm-linux-gnueabihf-gcc
arm-linux-gnueabihf-gcc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter 
/lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=71722376ff3af9eee5caf7bdfa2ecc350db0a590, not stripped
[klaus@klaus-x230 bin]$

Develop a Cross Compiled Program

Start Eclipse and create a new project:

RemoteDebugging.png

Notice the settings for the Cross GCC

On one of the next dialogues you have to specify what the prefix for the cross compiler tools are and where they resides.

RemoteDebugging1.png

In the project create a new C source file and fill in some "Hello World" stuff.

Save and compile (Ctrl+S, Ctrl+B).

In a console go to <path to your project>/Debug

]$ file <your binary (project name)>

Expect something like this:

[klaus@klaus-x230 Debug]$ file TestRemoteDBG 
TestRemoteDBG: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, 
interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.16, BuildID[sha1]=e8baff7637d637533f3730021407ffdc6d4c314e, not stripped
[klaus@klaus-x230 Debug]$ 

This tells us that the compiler has produced ARM executable code.