Compile COSMOS Core for the BeagleBone

Install the ARM Toolchain

The ARM toolchain consists of cross-compilers for ARM-based processors, such as the ones used on the BeagleBone and Raspberry Pi.

First check if you already have the cross-compiler by running the following a terminal window:

$ /usr/bin/arm-linux-gnueabihf-gcc-4.9

If you get a message saying No such file or directory, then you'll need to install the cross-compiler. Otherwise, you can skip to Clone COSMOS Core

Run the following command:

$ sudo gedit /etc/apt/sources.list

At the bottom of the file that opens, add the following two lines:

deb http://dk.archive.ubuntu.com/ubuntu/ xenial main
deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe

Save the file and close the window. Return the the terminal window and run:

$ sudo apt-get update
$ sudo apt-get install g++-4.9 gcc-4.9 gcc-4.9-arm-linux-gnueabihf g++-4.9-arm-linux-gnueabihf

Once this completes, open up the sources.list file again by running:

$ sudo gedit /etc/apt/sources.list

Remove the two lines you previously added at the bottom, and save the file.

Set up the Cross Compiler in Qt Creator

Open up Qt Creator, and click on Tools > Options.

Click on the Devices menu that appears near the bottom of the sidebar. Next, click the Add button.

Select Generic Linux Device and click Start Wizard. In the fields that appear, enter the following:

  • The name to identify this configuration: BeagleBoneBlack
  • The device's hostname or IP address: beaglebone.local
  • The username to log into the device: debian

Click Next, then Next again, and then Finish. Qt Creator will attempt to connect to the device, but you can cancel it for the time being.

Next, select Kits at the top of the sidebar.

Click the Add button on the right of the window. Enter the following text into the relevant fields:

  • Name: ARM32
  • File system name: arm32
  • Device type: Generic Linux Device
  • Device: BeagleBoneBlack
  • Compiler
    • C: GCC 4.9 (C, arm 32bit ...)
    • C++: GCC 4.9 (C++, arm 32bit ...)

Next, click OK.

Cross-Compile COSMOS Core

Now it's time to cross-compile for ARM.
In Qt Creator, click on File > Open File or Project..., and open up the file ~/cosmos/source/core/CMakeLists.txt.

TODO: a project configuration dialog might show up?

Once the project is finished loading, click the Projects button on the left side of the window, and then click on ARM32 (the kit we added in the previous step), and then click on Build under it.

Make sure the build directory looks something like:

/home/YOUR_USERNAME/cosmos/source/core/build-core-arm32-Debug

Now you can press CTRL + B (or the hammer icon at the bottom left) to build the project. This can take a while.

All of the executables are now located in the build directory from above. They are nested in a bunch of different folders, but we need to put them together all in the same folder. To do so, run the following command in a terminal (replacing YOUR_USERNAME with your username):

$ cd /home/YOUR_USERNAME/cosmos/source/core/build-core-arm32-Debug
$ mkdir bin
$ find ./ -perm /a+x -exec cp {} bin \;

Copy the Executables

Now you can copy the /home/YOUR_USERNAME/cosmos/source/core/build-core-arm32-Debug/bin folder to the /home/debian/cosmos/bin folder on the BeagleBone"

cd /home/YOUR_USERNAME/cosmos/source/core/build-core-arm32-Debug
rsync -auv ./bin debian@beaglebone.local:/cosmos/

Add COSMOS to PATH

If running the command agent from Cloud9 doesn't work, then the BeagleBone doesn't have the COSMOS bin folder added to the PATH variable. To add the folder, run the following in a Cloud9 terminal:

$ nano ~/.bashrc

This will open up the file containing the directories the shell looks for programs in. Now, add the following line to the bottom of the file:

export PATH="$HOME/cosmos/bin:$PATH"

After you've added that line, press CTRL + S to save the file, and then CTRL + X to exit.

Next, close the terminal window and open up a new one to reload the PATH. You should be able to run the following command to see the usage of the program:

$ agent

See Also

Tags: