3

How to add ev3dev libraries/headers to docker cross-compile setup?

I have assembled ev3dev on BrickPi (with Raspberry Pi 1 - chip BCM2835). I think, it all should be pretty similar for EV3 brick too. I do want to cross-compile and I have been able to download the docker image:

`ev3dev/debian-stretch-cross   latest    8e3b0aa8f243   4 years ago     732MB`
`ev3cc                         latest    8e3b0aa8f243   4 years ago     732MB`  

I access the compiler via docker run (docker run --rm -it -v /home/r0bis/src/robotics/helloArm/:/src -w /src ev3cc)
The compiler can compile hello world program that I can then put on RPI and run successfully. However when I try to compile examples that include ev3dev specific libraries it fails. In the tutorial I do not find what would be the best way to add the missing libraries. I thought that the libraries/headers would be included in the docker image; maybe they are and I just do not know something. Help would be much appreciated.

Screenshots

compiler@3547e87f257e:/src$ arm-linux-gnueabi-gcc port.c -o port
port.c:8:17: fatal error: ev3.h: No such file or directory
 #include "ev3.h"
                 ^
compilation terminated.

Desktop:

  • Manjaro Linux 64 bit
  • Connection Type: SSH over ethernet
  • Software: Text editor, ssh/sftp connection; would like to set up VSCode eventually

Robot:

  • Device: BrickPi 3 (Raspberry Pi 1 B+ (BCM2835)
  • Versions:

System info (from ev3dev-sysinfo)

Image file:         ev3dev-stretch-rpi-generic-2020-04-10
Kernel version:     4.14.114-ev3dev-2.3.5-rpi
Brickman:           0.10.3
BogoMIPS:           697.95
Bluetooth:          
Board:              board0
BOARD_INFO_HW_REV=0010
BOARD_INFO_MODEL=Raspberry Pi Model B Plus Rev 1.2
BOARD_INFO_SERIAL_NUM=00000000d374d92b
BOARD_INFO_TYPE=main
2
  • You might want to file a github issue with ev3dev. ev3dev.org/support explains how. Please drop a link to the github issue back here so folks can see how it goes.
    – chicks
    May 31, 2022 at 20:51
  • I have done so already and I am reading into docker technology as well. I will post all back here when it is solved
    – r0berts
    Jun 2, 2022 at 6:15

1 Answer 1

1

So the answer is mainly about usage of docker in context of cross compiling for RaspberryPi.

First we get the cross compiler docker image (you need to be part of docker group or use sudo):

docker pull ev3dev/debian-stretch-cross

That gives you the cross compiler environment, but to have ev3dev specific C headers, you need to get them there. They belong to https://github.com/in4lio/ev3dev-c and you need to compile and install them. Instructions are given in `https://github.com/in4lio/ev3dev-c/tree/stretch/docker/README.md' file - which you will also have if you do

mkdir -p ~/src
cd ~/src
git clone https://github.com/in4lio/ev3dev-c.git

Because I want the C development headers in place (they get put into /usr/local/include/) and not install every time I run the container I put them inside the Docker image. To do that I open the Dockerfile located inside ~/src/ev3dev-c/docker/ and make edits. They are not the best, probably, since I probably use sudo too much, but here is the modified Dockerfile:

FROM ev3dev/debian-stretch-cross:latest

RUN sudo apt-get update
RUN sudo apt-get install -y --no-install-recommends swig3.0 python-dev
RUN sudo apt-get install -y --no-install-recommends build-essential
RUN sudo apt-get install -y --no-install-recommends git
WORKDIR /home/robot
RUN sudo git clone https://github.com/in4lio/ev3dev-c.git
WORKDIR /home/robot/ev3dev-c
RUN sudo git submodule update --init --recursive
WORKDIR /home/robot/ev3dev-c/source/ev3/
RUN sudo make && sudo make install
RUN sudo make shared && make shared-install
RUN sudo rm -rf /var/lib/apt/lists/*

It works and the resulting image will be about 300 MB larger than ev3dev/debian-stretch-cross. In order to make the image file you change into the same directory as the Dockerfile is, make sure your 2 files you will need to execute have execute permissions (e.g. chmod ug+x ./build.sh) and run the build.sh file. After a little while it should successfully add ev3cc image to your docker images and you can now run it executing dock.sh

[user@computer ev3dev-c]$ docker images
REPOSITORY                    TAG       IMAGE ID       CREATED         SIZE
ev3cc                         latest    021f7f962c28   9 minutes ago   1.09GB

Before executing dock.sh though, change one directory up. The script mounts your current directory into a corresponding directory inside the container, where you can do the compilation. (And while you are at it, do not forget to examine Dockerfile and other small files in the same folder - they are very small scripts and pretty self-explanatory)

cd ..
./docker/dock.sh

then you will be put inside the container prompt and will be able to compile the hello example issuing make command:

compiler@ev3dev:/home/robot/ev3dev-c$ cd eg/hello/
compiler@ev3dev:/home/robot/ev3dev-c/eg/hello$ make
make -f ../Makefile.Debug
make[1]: Entering directory '/home/robot/ev3dev-c/eg/hello'
arm-linux-gnueabi-gcc -I. -I../../source/ev3 -I../../3d_party -O2 -std=gnu99 -W -Wall -Wno-comment -c hello.c -o ../../object/hello.o
arm-linux-gnueabi-gcc ../../object/modp_numtoa.o ../../object/brick.o ../../object/crc32.o ../../object/ev3.o ../../object/ev3_dc.o ../../object/ev3_led.o ../../object/ev3_light.o ../../object/ev3_port.o ../../object/ev3_sensor.o ../../object/ev3_servo.o ../../object/ev3_tacho.o ../../object/hello.o -o Debug/hello -lm 
***  Debug/hello ***
make[1]: Leaving directory '/home/robot/ev3dev-c/eg/hello'
compiler@ev3dev:/home/robot/ev3dev-c/eg/hello$
compiler@ev3dev:/home/robot/ev3dev-c/eg/hello$ ls -l Debug/
total 116
-rwxr-xr-x 1 compiler compiler 111140 Jun  3 11:26 hello
drwxr-xr-x 2 compiler compiler   4096 Jun  2 16:14 mingw

Now as you have seen your compiled hello example is in your Debug subdirectory and it is accessible to your host computer (because of -v volume mount from docker run options in dock.sh) as ~/src/ev3dev-c/eg/hello/Debug/

You can use any ssh transfer program such as FileZilla to transport the compiled hello binary to your robot and run it there - for example from ssh prompt. Connection to your robot via ssh is described here - but any tutorial how to connect to another computer via ssh will do. You just need to know either the IP address of your robot, or it's resolvable hostname on your local network:

robot@ev3dev:~$ ./hello
Hello, LEGO World!

So cross compilation works, but now for RaspberryPi (using BrickPi 3) I need to understand how to deal with the problem that brickpi3 does not automatically recognise motors or sensors plugged into the ports - i.e. supplied examples do not work. For EV3, though, things should be fine. - YES, checked - works fine for EV3.

AND Brickpi3 works fine too - it is just that instead of autodetection routines you need to supply which port number the motor is actually plugged in :-)

If you have not installed the ev3dev c libraries on your raspberrypi - not to worry, you can just tell the compiler to make the program with static libraries; file size is not very large (about 600 kb).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.