Step06 – Cross compiling

Cross compiling for the Beaglebone on Windows is not exactly straight forward in that there is a sea of downloads and options and it can be difficult filtering out the correct one!

Getting GCC running on Win32 Windows is pretty easy though, once you know which hoops to jump through. Let’s get started:

Get Linaro (arm-linux-gnueabi)

Windows

Get the arm-linux-gnueabi gcc binaries from the Linaro distribtion (NOTE: They only distribute the -gnueabihf version now, so you need to go back in their archives a bit to get the correct ABI version).

If you have the wrong ABI version, attempting to run the executable on the beaglebone will result in a message like:

“Cannot run executable”

Once you’ve got the executables, make sure the bin folder is in the path var of your current environment. You should be able to execute arm-linux-gnueabi-gcc –version from the command line and get a successful result.

Linux

Get the arm-linux-gnueabi toolchain for your distribution – it’s pretty straight forward. For example on Ubuntu:

[source]sudo apt-get install gcc-arm-linux-gnueabi[/source]

Compiling with arm-linux-gnueabi-gcc

Now create the ubiquitous Hello World! example:

[code language=”c”]
#include <stdio.h>

int main(int argc, char* argv[])
{
printf("Hello World!\n");
return 0;
}
[/code]

Save it as something like hello.c

Compile the example using

[source]arm-linux-gnueabi-gcc -march=armv7-a -mtune=cortex-a8 -mfpu=neon -o hello hello.c[/source]

Make sure you have SCP connected to the Beaglebone over a network link ( That is covered in Getting Started), and copy the resulting binary over to the BeagleBone.

In order to test the C++ compiler too, do a new Class based Hello World:

[code language=”c++”]
#include <iostream>

using namespace std;

class HelloWorld
{
public:
HelloWorld()
{
cout << "Hello Constructed World!" << endl;
}

~HelloWorld()
{
cout << "Goodbye Cruel World!" << endl;
}
};

int main(int argc, char* argv[])
{
HelloWorld hello;

return 0;
}
[/code]

Compile with almost the same line as with the previous example, but use the c++ compiler instead:

[source]arm-linux-gnueabi-g++ -march=armv7-a -mtune=cortex-a8 -mfpu=neon -o hellocpp hello.c[/source]

Again, copy the resulting binary file to the BeagleBone and run. You should see the class get constructed and de-constructed.

Using the toolchain with Code::Blocks

In order to develop with Code::Blocks, start Code::Blocks and let’s add a new compiler target. From the main menu select Settings->Compiler. Select GNU ARM GCC from the compiler options. You can point this compiler target to the arm-linux-gnueabi compiler if you want, but after a while of developing with ARM you may want more specific targets. Let’s create a new BeagleBone xCompile target:

Click Copy to make a copy of the GNU-ARM Compiler settings.

codeblocks-gnuarm-copy

Call the new compiler something like Beaglebone xCompile, and setup the toolchain executables settings page so that Code::Blocks can find the compiler you just downloaded:

codeblocks-gnuarm-toolchain

Setup some basic compiler flags on the compiler settings page. I always enable debugging symbols (they can always be stripped out afterwards if needed) and enable compiler warnings:

codeblocks-compiler-settings

Also, you need to tune the compiler to the previous command line we were using. So set the additional options:

[source]-march=armv7-a -mtune=cortex-a8 -mfpu=neon[/source]

codeblocks-gnuarm-xcompilesettings

Press OK (Finally) we’re done.

Now start a new console project.

Progress through the Project Wizard and when it comes to compiler selection, select your new compiler and click finish. The template for the project is infact a Hello World! example, so click Build.

Copy the resulting binary to the Beaglebone (again using SCP as mentioned before) and run it in a console. You should see Hello World! Yay (NOTE: You may need to make the file executable on the

Don’t be freaked out about the .exe extension – it is just that, an extension. Convention dictates that we think this is a Windows executable file though, so it’s best to change the Code::Blocks project properties to change the generated file extension.

You can of course setup a project wizard for Beaglebone, but I’ll leave that up to you.

One thought on “Step06 – Cross compiling

  1. coderszhub@gmail.com

    It has to be much more in detail.
    Personally I lost the track of it and got unable to setup an environment to build apps for Beaglebone.

Leave a Reply