Instructions for Cmake on Raspberry Pi Zero are inaccurate

The instructions for Tensorflow Lite cross compilation for ARM are inaccurate (contain errors/omissions, as far as I can see), as follows:

  1. In the PREREQUISITES section it states " You need CMake installed and downloaded TensorFlow source code. Please check Build TensorFlow Lite with CMake page for the details."
    To be more accurate you need to execute step 1 and 2 shown on that referenced page. Step 3 also needs to be done but not yet.

  2. In the section " Build for Raspberry Pi Zero (ARMv6)" and then the instructions for “download toolchain” a second line should be added that reads “mkdir -p ${HOME}/toolchains” This line is shown in the instructions for the other builds but not in the instructions for the Raspberry Pi Zero. Without creating this directory, the next statements will fail.

  3. After installing the toolchains but before running cmake you need to execute step 3 of the PREREQUISITES, being:
    mkdir tflite_build
    cd tflite_build
    since the cmake statement needs to be run from that directory.

  4. If you then execute the cmake statement as shown it will fail, throwing errors as follows:

4a) first error “CMake Error: The source directory “/home/tensorflow/lite” does not exist.” this is because the directory should be “/home/tensorflow_src/tensorflow/lite” instead. You should add “/tensorflow_src” to the cmake statement “…/tensorflow/lite”

4b) running it again then throws the error (not the complete text shown):
The C compiler identification is unknown
– The CXX compiler identification is unknown
– Detecting C compiler ABI info
– Detecting C compiler ABI info - failed
– Check for working C compiler: /home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc
– Check for working C compiler: /home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc - broken
CMake Error at /usr/share/cmake-3.18/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
is not able to compile a simple test program. (etc etc etc rest of text not copied.)

I was not sure how to correct this but I removed the ${ARMCC_PREFIX} for the gcc and g++ compiler in the cmake statement, just using the compilers already installed. At least it finds the compilers and starts the process. (if I change it to use 8.3.0. instead of 6.5.0 it also fails)

4c) Cmake gives a lot of positive messages about progress but then at the end reports the errors:
Looking for a Fortran compiler
– Looking for a Fortran compiler - NOTFOUND
– Could NOT find CLANG_FORMAT: Found unsuitable version “0.0”, but required is exact version “9” (found CLANG_FORMAT_EXECUTABLE-NOTFOUND)

so I installed a fortran compiler with “sudo apt-get install gfortran”. Nowhere this is mentioned as a prerequisite.

It still reports failures on the following points, not sure whether this is due to changing the compiler path or anything else, or how to solve it. All other message are positive.
– Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
– Performing Test COMPILER_SUPPORT_Wshorten64to32 - Failed
– Performing Test COMPILER_SUPPORT_Wenumconversion - Failed
– Performing Test COMPILER_SUPPORT_Wcpp11extensions - Failed
– Performing Test COMPILER_SUPPORT_wd981 - Failed
– Performing Test COMPILER_SUPPORT_wd2304 - Failed

4d) Running cmake again now still reports
Could NOT find CLANG_FORMAT: Found unsuitable version “0.0”, but required is exact version “9” (found CLANG_FORMAT_EXECUTABLE-NOTFOUND)
while the other messages all look positive. (except for the tests shown at 4c above)

I don’t know whether this message about clang-format is critical and I don’t know what to do to solve it.

Also I have not tested running tensorflow yet after these steps.

I am running a Raspberry Pi Zero W v1.1 with updated and upgraded Bullseye OS (Dec 17, 2021).

So to summarise, the final cmake statement I used was as follows (running from the tflite_build directory):

(note: somehow the forum adds 3 dots in front of “…/tensorflow_src/etc” , should just be 2.)

  1. For clarity it could be added that step 5 or 6 of the page referenced in the PREREQUISITES should then be executed.
1 Like

Thanks for the feedback @Willem, looping in @xhae

Also looping in @yyoon and @Thai_Nguyen

Just to let you know I interrupted the build process. After approx.12 hours it did not get past 17% and it did not show any more progress in the last 10 hours. So I think I have tried all kinds of ways to get Tensorflow working. I’ll probably have to do with the object recognition capabilities of OpenCV and skip on using Tensorflow.

I just realized something… these instructions are made for cross compilation for a Raspberry Pi Zero but not for compiling on a Raspberry Pi Zero? oops

So better use a Linux installation on my PC to do this? And move it over to the Raspberry afterwards using docker?

Yes It is crosscompilation on the Linux host.

You can prepare the installable wheel from the linux host with rpi0:

O.K. please check and comment my plan of approach before I spend another few days getting nowhere…

So far, I have a PC just running Windows 10 or 11, and a few Raspberry Pi Zero’s running Buster or Bullseye. My goal is to play around with the tflite_runtime on the Raspberry Pi Zero to control a robot. (alternatively I will do the same just using OpenCV)

Having tried and failed the Python quickstart (probably because it is for other Pi’s, but not for the Zero) and having tried the compilation on the Zero itself (cancelled because it gets stuck), I now want to try the Python wheel approach.

But I am new to using Docker. Did some reading…

The plan:

  1. install WSL2 on my PC with Ubuntu distribution.
    Q1: or should I use a multi-boot setup Windows/Ubuntu instead of WSL2?
    Q2: or should I use Debian instead of Ubuntu within WSL2?
  2. Load and start the tensorflow:devel docker image within the Ubuntu WSL environment (is this step required?)
  3. Install cmake and download the Tensorflow source code (i.e. step 1 and 2 of the Cmake overview explanation) within the docker image
  4. Run the command:
    tensorflow/tools/ci_build/ PI-PYTHON39 \ tensorflow/lite/tools/pip_package/ rpi0
    (since I have Python 3.9 within Bulleseye on a Raspberry Pi Zero with ARMv6)

Or, instead of using Piwheels, should I still do the ARM cross compilation using Cmake instead of step 4 above?

And what happends after the above? How to move the result then onto the Pi Zero?

Thanks for your assistance.

You will have an output wheel package that could be installed on your Raspberry with pip install

First thing I tried now is run the cmake again but now within the docker container on Ubuntu within WSL2.

It still required the corrections as mentioned in my first post above:

  1. As indeed mentioned on the site, cmake needs to be installed, but now step 2 can be skipped since the tensorflow_src is already part of the image (as mentioned on the site as well)
  2. the mkdir -p ${HOME}/toolchains command needs to be added to the instructions for the toolchain
  3. step 3 needs to be done
    4a) the tensorflow_src directory needs to be added to the path in the cmake command
    4b) this time there are no errors on the gcc and g++ compiler (so the ARMCC_PREFIX in the cmake command can be left as-is)
    4c) the fortran compiler needs to be installed as a prerequisite
    4d) the cmake runs with similar positive and negative messages as before
    Here is the output (with some of the positive messages replaced by etc etc)
    – Setting build type to Release, for debug builds use’-DCMAKE_BUILD_TYPE=Debug’.
    – The C compiler identification is GNU 6.5.0
    – The CXX compiler identification is GNU 6.5.0
    – etc etc
    – Performing Test CMAKE_HAVE_LIBC_PTHREAD
    – Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
    – Looking for pthread_create in pthreads
    – Looking for pthread_create in pthreads - not found
    – etc etc
    – Performing Test COMPILER_SUPPORT_Wshorten64to32 - Failed
    – etc etc
    – Performing Test COMPILER_SUPPORT_Wenumconversion - Failed
    – Performing Test COMPILER_SUPPORT_Wcpp11extensions
    – Performing Test COMPILER_SUPPORT_Wcpp11extensions - Failed
    – etc etc
    – Performing Test COMPILER_SUPPORT_wd981
    – Performing Test COMPILER_SUPPORT_wd981 - Failed
    – Performing Test COMPILER_SUPPORT_wd2304
    – Performing Test COMPILER_SUPPORT_wd2304 - Failed
    – etc etc
    – Could NOT find CLANG_FORMAT: Found unsuitable version “10.0.0”, but required is exact version “9” (found /usr/bin/clang-format)
    – etc etc
    – Build files have been written to: /tflite_build

Running step 6 (the cmake build command) after this goes well until 79%. Then it starts throwing a lot of internal compiler errors. Here is a small sample:

make[3]: *** [CMakeFiles/tensorflow-lite.dir/build.make:872: CMakeFiles/tensorflow-lite.dir/kernels/] Error 4
arm-rpi-linux-gnueabihf-g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See for instructions.
make[3]: *** [CMakeFiles/tensorflow-lite.dir/build.make:1041: CMakeFiles/tensorflow-lite.dir/kernels/] Error 4
make[3]: Leaving directory ‘/tflite_build’
make[2]: *** [CMakeFiles/Makefile2:1258: CMakeFiles/tensorflow-lite.dir/all] Error 2
make[2]: Leaving directory ‘/tflite_build’
make[1]: *** [CMakeFiles/Makefile2:5203: examples/label_image/CMakeFiles/label_image.dir/rule] Error 2
make[1]: Leaving directory ‘/tflite_build’
make: *** [Makefile:1710: label_image] Error 2

I realise this feedback is a mix of “site feedback” and “user experience”. I hope it is still useful.

Now I will move on to the python wheel approach…

Now I did the python wheel approach, as follows:

  1. start Ubuntu within WSL2
  2. docker run --name wdtest -it tensorflow/tensorflow:devel
  3. sudo apt-get cmake
  4. sudo apt-get install gfortran (just to be sure…)
  5. cd tensorflow_src
  6. tensorflow/tools/ci_build/ PI-PYTHON39 tensorflow/lite/tools/pip_package/ rpi0

and get the following:

WORKSPACE: /tensorflow_src
COMMAND: tensorflow/lite/tools/pip_package/ rpi0
CI_COMMAND_PREFIX: ./tensorflow/tools/ci_build/builds/with_the_same_user ./tensorflow/tools/ci_build/builds/configured pi-python39
CONTAINER_TYPE: pi-python39
BUILD_TAG: tf_ci
(docker container name will be tf_ci.pi-python39)

Building container (tf_ci.pi-python39)…
tensorflow/tools/ci_build/ line 145: docker: command not found
ERROR: docker build failed. Dockerfile is at /tensorflow_src/tensorflow/tools/ci_build/Dockerfile.pi-python39

It is trying to build a docker container within a docker container? I will now try it without step 2 (docker run) above and adding the tensorflow_src download (clone).

So now I tried it without running the docker first, as follows:

  1. start Ubuntu within WSL2
  2. sudo apt-get cmake
  3. sudo apt-get install gfortran (just to be sure…)
  4. git clone GitHub - tensorflow/tensorflow: An Open Source Machine Learning Framework for Everyone tensorflow_src (note: the forum editor messes up here, this should be displayed as step 2 of the prerequisite instructions to Clone TensorFlow repository but it somehow changes the display and I don’t know how to undo this)
  5. cd tensorflow_src
  6. tensorflow/tools/ci_build/ PI-PYTHON39 tensorflow/lite/tools/pip_package/ rpi0

Now the process starts running with a lot of progress messages, but:

  1. the cmake command still throws the same warnings/errors as reported in point 4c of my first post above. Nevertheless the build after that still continues
  2. the build command progresses up to 98% (Building CXX object CMakeFiles/tensorflow-lite.dir/ and then after 4 more long g++ commands waits some time, before throwing the error message:

ERRO[0169] error waiting for container: invalid character ‘u’ looking for beginning of value

Note it did create a container called tf_ci.pi-python39

I think I have exhausted all options now and am giving up until there is some feedback to solve this.

I managed to transfer the docker container that was created in the above process to the raspberry pi zero (using save to tar, ftp and load from tar) and get the following message when I try to run it on the raspberry:

WARNING: The requested image’s platform (linux/amd64) does not match the detected host platform (linux/arm/v6) and no specific platform was requested
standard_init_linux.go:228: exec user process caused: exec format error

and when I inspect the docker either on the Raspberry Pi or in the Ubuntu environment on the PC it shows the linux OS and amd64 architecture.

Are you running tensorflow/tools/ci_build/ PI-PYTHON39 tensorflow/lite/tools/pip_package/ rpi0 inside a container or on the host?

First I tried running it within a container ( step 2 was “docker run --name wdtest -it tensorflow/tensorflow:devel”, step 3 to 6 were within the container). After that had failed (probably because it tried creating a container within a container and the docker command was not installed in the container) I ran it directly on the host (Ubuntu within WSL), after first downloading the required source code. It then created a container as result.

Since this process should have resulted in a pip wheel I also inspected the contents of the container that was created (tf_ci.pi-pytho39) for any wheel files. This is what was found:

Have you tried to install docker in the wsl2 Linux os?

What I meant is that is for a Linux host with docker.


I have tried:

  1. the Python quickstart guide for Raspberry PI in different ways as described here and here, both with pre-installing OpenCV and without.
    After installation this is failing on the statement "“from tflite_runtime import _pywrap_tensorflow_interpreter_wrapper as _interpreter_wrapper” as explained in my other post.
  2. the Cmake compilation on the Raspberry PI. I interrupted the build process after 12 hours because it got stuck.
  3. the Cmake cross compilation on Ubuntu within WSL2, within the tensorflow/tensorflow:devel container. It failed after 79% as described, throwing a lot of compiler errors.
  4. the Python wheel approach within the tensorflow/tensorflow:devel container. This failed because it can’t find the docker command within that container (it tries to create a container within a container)
  5. the Python wheel approach on Ubuntu within WSL2, but without using the tensorflow/tensorflow:devel container. This gets up to 98% and then fails with the error “ERRO[0169] error waiting for container: invalid character ‘u’ looking for beginning of value”

So the answer to your latest question is yes. This is point 5 above. That process does create a new container called tf_ci.pi-python39 and tries to run within that container. The build_pip_package starts and runs up to 98% but does not completely finish, as explained.

Are you able to successful run docker run hello-world in your Ubuntu/WSL2?

Yes, no problem to run the hello-world docker in Ubuntu on WSL2.

And I have already described that it is no problem to install and run commands within the tensorflow/tensorflow:devel docker image or to create a new docker image called cf_ti:pi-python39 and then run commands within it. There are just specific commands related to the tensorflow installation script that fail.

I don’t know if it is a specific WSL2 issue but with a standard linux host + docker with:

tensorflow/tools/ci_build/ PI-PYTHON39 tensorflow/lite/tools/pip_package/ rpi0 

I’ve produced the raspberry p0 wheel:


The only problem I see is:


As it is probably a CI only env variable and it is going to not limit the number of parallel jobs in the compilation exhausting host resources.

I suggest as a temp workaround to substitute that variable with the number of available cores on you host.