Torizon: Building Python modules in Arm64 with aarch64-linux-gnu-gcc

Hi team,

I’m trying to use the RaspPi Sense hat, and since the module is not available in the feeds, I’m building it myself.

I could manage most of the dependencies (Pillow being the most troublesome) but when trying to run the program, I’m missing RTIMULib: RTIMULib/Linux/python at master · RPi-Distro/RTIMULib · GitHub.

So, I’m looking to also build it but I get an error with aarch64-linux-gnu-gcc.

Step 10/14 : RUN cd rtimulib/Linux/python && python3 setup.py build
 ---> Running in b110a9325bbc
running build
running build_ext
building 'RTIMU' extension
creating build
creating build/temp.linux-aarch64-3.7
creating RTIMULib
creating RTIMULib/IMUDrivers
aarch64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DHAL_QUIET -I../../RTIMULib -I/usr/include/python3.7m -c PyRTIMU.cpp -o build/temp.linux-aarch64-3.7/PyRTIMU.o -std=c++0x
error: command 'aarch64-linux-gnu-gcc' failed with exit status 1
ERROR: Service 'rpi-hats-python' failed to build: The command '/bin/sh -c cd rtimulib/Linux/python && python3 setup.py build' returned a non-zero code: 1

What I’ve been reading mostly suggest to install python3-dev, which is already installed. I also tried to go through the cross-compiling route but it doesn’t seem to work either (it gets built in x86_64).

Am I missing something in the Dockerfile? Dockerfile:

ARG IMAGE_ARCH=arm64v8
# For Apalis iMX8 use IMAGE_ARCH=arm64v8

FROM torizon/$IMAGE_ARCH-debian-base:buster

RUN apt-get update \
    && apt-get install -y --no-install-recommends python3 \
    python3-setuptools \
    python3-influxdb \   
    wait-for-it \
    python3-pip \
    && apt-get clean && apt-get autoremove && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install -y procps
RUN apt-get update && apt-get install -y python3-dev

RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install --upgrade Pillow
RUN pip3 install numpy

COPY RTIMULib rtimulib
RUN cd rtimulib/Linux/python && python3 setup.py build

COPY sense-hat sense-hat
RUN cd sense-hat && python3 setup.py install

COPY rpi-hats-python.py /usr/bin

ENTRYPOINT ["python3","/usr/bin/rpi-hats-python.py"]

#ENTRYPOINT ["wait-for-it", "influxdb:8086", "-t", "60", "--", "/bin/bash"]

Complete Docker build log:

alvaro@alvaro-toradex:~/Toradex/FATorizonDemo/RaspPiDemo/Source$ docker-compose up --build
Building rpi-hats-python
Step 1/14 : ARG IMAGE_ARCH=arm64v8
Step 2/14 : FROM torizon/$IMAGE_ARCH-debian-base:buster
# Executing 1 build trigger
 ---> Using cache
 ---> b2ce468568e7
Step 3/14 : RUN apt-get update     && apt-get install -y --no-install-recommends python3     python3-setuptools     python3-influxdb     wait-for-it     python3-pip     && apt-get clean && apt-get autoremove && rm -rf /var/lib/apt/lists/*
 ---> Using cache
 ---> af6c4105a100
Step 4/14 : RUN apt-get update && apt-get install -y procps
 ---> Using cache
 ---> 2248cc66e341
Step 5/14 : RUN apt-get update && apt-get install -y python3-dev
 ---> Using cache
 ---> 5e4f0506391e
Step 6/14 : RUN python3 -m pip install --upgrade pip
 ---> Using cache
 ---> 7caede36f471
Step 7/14 : RUN python3 -m pip install --upgrade Pillow
 ---> Using cache
 ---> f4f321bcf3ed
Step 8/14 : RUN pip3 install numpy
 ---> Using cache
 ---> 93794d7f47cc
Step 9/14 : COPY RTIMULib rtimulib
 ---> Using cache
 ---> 9b51dfbc3ee4
Step 10/14 : RUN cd rtimulib/Linux/python && python3 setup.py build
 ---> Running in 6fd9c94d494e
running build
running build_ext
building 'RTIMU' extension
creating build
creating build/temp.linux-aarch64-3.7
creating RTIMULib
creating RTIMULib/IMUDrivers
aarch64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DHAL_QUIET -I../../RTIMULib -I/usr/include/python3.7m -c PyRTIMU.cpp -o build/temp.linux-aarch64-3.7/PyRTIMU.o -std=c++0x
error: command 'aarch64-linux-gnu-gcc' failed with exit status 1
ERROR: Service 'rpi-hats-python' failed to build: The command '/bin/sh -c cd rtimulib/Linux/python && python3 setup.py build' returned a non-zero code: 1

Thanks, Alvaro.

So I actually found out I could install sense-hat directly with pip after updating it. However, RTIMULib was still needed, and for some reason the pip method not work as well because the headers are not included.

After installing gcc, g++, make and with the cloned RTIMULib this worked.

RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install --upgrade Pillow
RUN python3 -m pip install --upgrade sense-hat
RUN pip3 install numpy

RUN apt-get install gcc g++ make
COPY RTIMULib rtimulib
RUN cd rtimulib/Linux/python && python3 setup.py build && python3 setup.py install

Now there are sense-hat related issues because of using this in a device that is not the RPi, but it is unrelated to this question. As a heads-up, it might require cloning the sense-hat project and make proper changes and build/install instead of using the sense-hat found in Pip.