Answers.Body: <p>So the answer is mainly about usage of <code>docker</code> in context of cross compiling for RaspberryPi.</p>
  <p>First we get the cross compiler docker image (you need to be part of <code>docker</code> group or use sudo):</p>
  <pre><code>docker pull ev3dev/debian-stretch-cross
  </code></pre>
  <p>That gives you the cross compiler environment, but to have ev3dev specific C headers, you need to get them there. They belong to <code>https://github.com/in4lio/ev3dev-c</code> 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</p>
  <pre><code>mkdir -p ~/src
  cd ~/src
  git clone https://github.com/in4lio/ev3dev-c.git
  </code></pre>
  <p>Because I want the C development headers in place (they get put into <code>/usr/local/include/</code>) 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 <code>~/src/ev3dev-c/docker/</code> and make edits. They are not the best, probably, since I probably use sudo too much, but here is the modified Dockerfile:</p>
  <pre><code>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 &amp;&amp; sudo make install
  RUN sudo make shared &amp;&amp; make shared-install
  RUN sudo rm -rf /var/lib/apt/lists/*
  </code></pre>
  <p>It works and the resulting image will be about 300 MB larger than <code>ev3dev/debian-stretch-cross</code>. 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. <code>chmod ug+x ./build.sh</code>) and run the <code>build.sh</code> file. After a little while it should successfully add <code>ev3cc</code> image to your docker images and you can now run it executing <code>dock.sh</code></p>
  <pre><code>[user@computer ev3dev-c]$ docker images
  REPOSITORY                    TAG       IMAGE ID       CREATED         SIZE
  ev3cc                         latest    021f7f962c28   9 minutes ago   1.09GB
  
  </code></pre>
  <p>Before executing <code>dock.sh</code> 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)</p>
  <pre><code>cd ..
  ./docker/dock.sh
  </code></pre>
  <p>then you will be put inside the container prompt and will be able to compile the hello example issuing <code>make</code> command:</p>
  <pre><code>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
  
  </code></pre>
  <p>Now as you have seen your compiled hello example is in your <code>Debug</code> subdirectory and it is accessible to your host computer (because of <code>-v</code> volume mount from <code>docker run</code> options in <code>dock.sh</code>) as <code>~/src/ev3dev-c/eg/hello/Debug/</code></p>
  <p>You can use any ssh transfer program such as <em>FileZilla</em> to transport the compiled <code>hello</code> binary to your robot and run it there - for example from ssh prompt. Connection to your robot via ssh is described <a href="https://www.ev3dev.org/docs/tutorials/connecting-to-ev3dev-with-ssh/" rel="nofollow noreferrer">here</a>  - 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:</p>
  <pre><code>robot@ev3dev:~$ ./hello
  Hello, LEGO World!
  </code></pre>
  <p>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 <code>EV3</code>, though, things should be fine. - YES, checked - works fine for EV3.</p>
  <p><strong>AND</strong> Brickpi3 works fine <a href="https://github.com/ev3dev/ev3dev/issues/1534#event-6738268871" rel="nofollow noreferrer">too</a> - it is just that instead of autodetection routines you need to supply which port number the motor is actually plugged in :-)</p>
  <p>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).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-03T11:40:54.817Z
Answers.LastActivityDate: 2022-06-12T10:22:39.257Z
Answers.LastEditDate: 2022-06-12T10:22:39.257Z
Answers.UserDisplayName: r0berts
Body: <p><strong>How to add ev3dev libraries/headers to docker cross-compile setup?</strong></p>
  <p>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:</p>
  <pre><code>`ev3dev/debian-stretch-cross   latest    8e3b0aa8f243   4 years ago     732MB`
  `ev3cc                         latest    8e3b0aa8f243   4 years ago     732MB`  
  </code></pre>
  <p>I access the compiler via <code>docker run</code> (<code>docker run --rm -it -v /home/r0bis/src/robotics/helloArm/:/src -w /src ev3cc</code>)<br />
  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.</p>
  <p><strong>Screenshots</strong></p>
  <pre><code>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 &quot;ev3.h&quot;
                   ^
  compilation terminated.
  
  </code></pre>
  <p><strong>Desktop:</strong></p>
  <ul>
  <li>Manjaro Linux 64 bit</li>
  <li>Connection Type: SSH over ethernet</li>
  <li>Software: Text editor, ssh/sftp connection; would like to set up VSCode eventually</li>
  </ul>
  <p><strong>Robot:</strong></p>
  <ul>
  <li>Device: BrickPi 3 (Raspberry Pi 1 B+ (BCM2835)</li>
  <li>Versions:</li>
  </ul>
  <p><strong>System info (from <code>ev3dev-sysinfo</code>)</strong></p>
  <pre><code>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
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-05-31T20:51:24.810Z
Comments.Text: You might want to file a github issue with ev3dev.  https://www.ev3dev.org/support/ explains how.  Please drop a link to the github issue back here so folks can see how it goes.
Comments.UserDisplayName: chicks
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-06-02T06:15:02.243Z
Comments.Text: I have done so already and I am reading into docker technology as well. I will post all back here when it is solved
Comments.UserDisplayName: r0berts
Tags: <programming><tools><ev3dev>
Title: How to cross compile for ev3dev using Docker
UserDisplayName: r0berts
ThreadText: # How to cross compile for ev3dev using Docker
  
  (Asked by: username_0 on 2022-05-29)
  
  **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
  
  ```
  
  **Tags:** programming, tools, ev3dev
  
  > **Comments:**
  > **username_1**: You might want to file a github issue with ev3dev.  https://www.ev3dev.org/support/ explains how.  Please drop a link to the github issue back here so folks can see how it goes.  
  > **username_0**: I have done so already and I am reading into docker technology as well. I will post all back here when it is solved  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-06-03. Score: 1 | Accepted answer
  
  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](https://www.ev3dev.org/docs/tutorials/connecting-to-ev3dev-with-ssh/) - 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](https://github.com/ev3dev/ev3dev/issues/1534#event-6738268871) - 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).
  
  
  ---
  
  