Cross compile for BeagleBone Black in Eclipse with Docker

Cross compile for BeagleBone Black in Eclipse with Docker

Initial situation #

If you want to cross compile for the ARM plattform BeagleBone Black, you need to have the cross compiler arm-linux-gnueabihf- installed on your system. In most distributions the compiler can be installed via the package manager. If you are using an IDE like Eclipse you can set up a new cross project and choose arm-linux-gnueabihf- as compiler. Eclipse will find the correct compiler in $PATH. At someday I ran into the problem that my compiled programm was not executable on the target. The error message was following:

/usr/lib/arm-linux-gnueabihf/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /root/test_application)

After some research I came to the conclusion that versions of compiler / libs etc. were not matching on my development machine and the target. This is basically because the target has a working version of Linux that is not getting updated. I asked myself how to get an older version of the appropriate compiler to run on my development machine?

Solution #

after doing some research I came across Docker. My idea was to setup a image in Docker which matches exactly the versions I need to compile for my target.

Realization #

Install Docker on Manjaro #

To install Docker in Manjaro Linux you need to run

$ sudo pacman -Syu

to update your system. After that you can install Docker via

$ sudo pacman -S docker

After the installation is completed you have to make sure that Docker service ist started and you can enable a start on every reboot.

$ sudo systemctl start docker.service
$ sudo systemctl enable docker.service

To check the installation and the version you can run

$ sudo docker version

Testing installation #

Another way to test the installation is to run the hello-wold image.

$ sudo docker run hello-world

If everything is allright you will get a message like

Hello from Docker!
This message shows that your installation appears to be working correctly.

Docker without root #

In the default configuration you have to be logged in as root or use the sudo command everytime you want to execute a Docker command. To remove that you have to add your user to the docker group. For that run this command

$ sudo usermod -aG docker $USER

After rebooting the system you can use Docker without the sudo command.

Install Docker on Ubuntu #

I would recommend to use the official guide on https://docs.docker.com/engine/install/ubuntu/ to install Docker on Ubuntu.

Creating a cross compile image for the BeagleBone Black #

In my case I was using a Debian (stretch) Linux on my target. So I had to create a Docker image with the same version. First of all I created a Dockerfile with the following content

FROM debian:stretch
RUN apt-get update && apt-get install -y \
ssh \
gcc \
gcc-arm-linux-gnueabihf \
g++-arm-linux-gnueabihf \
make \
&& rm -rf /var/lib/apt/lists/*

The file just needs to have the name Dockerfile. After saving the file I build the image (inside the directory where the Dockerfile is located) with the command (note the dot at the end of the line)

$ docker build --tag debian_stretch_crossbuild:1.0 .

After building I can start an interactive shell inside the image with

$ docker run -it --name test debian_stretch_crossbuild:1.0

You can close the session with the command exit. After that I pushed the image to Docker Hub as a public repository. If you want to use this image you can pull it with following command

$ docker pull donpadde/debian_stretch_crossbuild:1.0

Integrating Docker in Eclipse #

!!! This section gets an in detail update in the next days !!!
If you want to use a Docker container in Eclipse you have to install two plugins inside Eclipse. C/C++ Docker Container Launch Support Developer Resources and Docker Tooling. Create a new C++ project and choose Cross GCC. The toolchain is called arm-linux-gnueabihf-. After that you can edit your project settings. Right click on your project -> project properties. Then C/C++ -> settings -> container settings. Check build inside docker image and choose the image. Don’t forget to apply the changes.