{"id":18968856,"url":"https://github.com/tttapa/rpi-cpp-toolchain","last_synced_at":"2025-06-22T23:03:16.976Z","repository":{"id":38346513,"uuid":"208371689","full_name":"tttapa/RPi-Cpp-Toolchain","owner":"tttapa","description":"C/C++ cross-compilation toolchain for Raspberry Pi, cross-compilation of OpenCV and other libraries, and an example C++ project.","archived":false,"fork":false,"pushed_at":"2022-05-01T18:58:35.000Z","size":1124,"stargazers_count":40,"open_issues_count":3,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T08:51:09.379Z","etag":null,"topics":["cmake","cpp","cross-compiler","debugging","docker","gcc","gdb","opencv","python","python38","raspberry-pi"],"latest_commit_sha":null,"homepage":"https://tttapa.github.io/Pages/Raspberry-Pi/C++-Development/index.html","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tttapa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-14T01:18:20.000Z","updated_at":"2025-03-18T12:26:35.000Z","dependencies_parsed_at":"2022-09-21T03:01:03.301Z","dependency_job_id":null,"html_url":"https://github.com/tttapa/RPi-Cpp-Toolchain","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tttapa%2FRPi-Cpp-Toolchain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tttapa%2FRPi-Cpp-Toolchain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tttapa%2FRPi-Cpp-Toolchain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tttapa%2FRPi-Cpp-Toolchain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tttapa","download_url":"https://codeload.github.com/tttapa/RPi-Cpp-Toolchain/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249213758,"owners_count":21231096,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmake","cpp","cross-compiler","debugging","docker","gcc","gdb","opencv","python","python38","raspberry-pi"],"created_at":"2024-11-08T14:48:39.728Z","updated_at":"2025-04-19T14:45:05.465Z","avatar_url":"https://github.com/tttapa.png","language":"Shell","readme":"\u003cdiv align=\"center\"\u003e\n\n| **Note**: The toolchains themselves have been moved to a separate repository:\u003cbr\u003e[tttapa/docker-arm-cross-toolchain](https://github.com/tttapa/docker-arm-cross-toolchain) |\n|:---:|\n\n\u003c/div\u003e\n\n---\n\n[![Download from Docker Hub](https://img.shields.io/docker/pulls/tttapa/docker-arm-cross-build-scripts?label=Docker%20Hub\u0026logo=docker)](https://hub.docker.com/r/tttapa/docker-arm-cross-build-scripts/tags)\n\n# Raspberry Pi C++ Toolchain\n\nThis repository contains all you need to develop and cross-compile C++ applications for the Raspberry Pi (both 32 and 64 bit).\nTopics covered:\n\n 1. Building or installing a cross-compilation toolchain\n 2. Cross-compiling common libraries such as OpenCV\n 3. Cross-compiling your own C++ project\n 4. Deploying the software to the Pi\n 5. Remote on-target debugging\n\nIt has cross-compiled versions of many useful libraries and tools:\n\n - **Zlib**: compression library (OpenSSL and Python dependency)\n - **OpenSSL**: cryptography library (Python dependency)\n - **FFI**: foreign function interface (Python dependency, used to call C functions using ctypes)\n - **Bzip2**: compression library (Python dependency)\n - **GNU ncurses**: library for text-based user interfaces (Python dependency, used for the console)\n - **GNU readline**: library for line-editing and history (Python dependency, used for the console)\n - **GNU dbm**: library for key-value data (Python dependency)\n - **SQLite**: library for embedded databases (Python dependency)\n - **UUID**: library for unique identifiers (Python dependency)\n - **libX11**: X11 protocol client library (Tk dependency)\n - **Tcl/Tk**: graphical user interface toolkit (Python/Tkinter dependency)\n - **Python 3.10.4**: Python interpreter and libraries\n - **ZBar**: Bar and QR code decoding library\n - **Raspberry Pi Userland**: VideoCore GPU drivers\n - **VPX**: VP8/VP9 codec SDK\n - **x264**: H.264/MPEG-4 AVC encoder\n - **Xvid**: MPEG-4 video codec\n - **FFmpeg**: library to record, convert and stream audio and video\n - **OpenBLAS**: linear algebra library (NumPy dependency)\n - **NumPy**: multi-dimensional array container for Python (OpenCV dependency)\n - **SciPy**: Python module for mathematics, science, and engineering\n - **OpenCV 4.5.5**: computer vision library and Python module\n - **GDB Server**: on-target remote debugger\n - **GNU Make**: build automation tool\n - **Ninja**: build system\n - **CMake**: build system\n - **Distcc**: distributed compiler wrapper (uses your computer to speed up compilation on the Pi)\n - **CCache**: compiler cache\n - **cURL**: tool and library for transferring data over the network (Git dependency)\n - **Git**: version control system\n \u003c!-- - **GCC 11.1.0**: C, C++ and Fortran compilers --\u003e\n\nAdditionally, there are examples for cross-compiling Python C, C++ and Cython \nextensions.\n\n## Documentation\n \nThe documentation is still a work in progress, but parts of it are already available here:  \n[**Documentation**](https://tttapa.github.io/Pages/Raspberry-Pi/C++-Development/index.html)\n\nThe main script is [`docker-arm-cross-build-scripts/build.sh`](https://github.com/tttapa/docker-arm-cross-build-scripts/blob/main/build.sh),\nexecute it without any flags to print the usage information:\n\n```txt\n./docker-arm-cross-build-scripts/build.sh\n```\n```txt\nBuild or pull the Raspberry Pi GCC toolchain and cross-compiled libraries.\n\nUsage\n    ./docker-arm-cross-build-scripts/build.sh \u003cboard\u003e [--dev] [--push] [--pull] [--export] [--buildx]\n\nBoards\n    rpi\n        Raspberry Pi 1, 32-bit.\n        Recommended for: RPi A/B/A+/B+, CM 1, RPi Zero/Zero W\n\n    rpi3-armv8\n        Raspberry Pi 3, 32-bit.\n        Recommended for: RPi 2B rev. 1.2, RPi 3B/3B+, CM 3, RPi 4B/400, CM 4, RPi Zero 2 W\n\n    rpi3-aarch64\n        Raspberry Pi 3, 64-bit.\n        Recomended for: RPi 2B rev. 1.2, RPi 3B/3B+, CM 3, RPi 4B/400, CM 4, RPi Zero 2 W\n\nOptions\n    --dev\n        Cross-compile the development tools as well (e.g. distcc, ccache, CMake, Git, Ninja, Make)\n\n    --push\n        After building, push the resulting image to Docker Hub\n\n    --pull\n        Don't build the image locally, pull everything from Docker Hub\n\n    --export\n        Export the toolchain, sysroot and staging area to your computer\n\n    --buildx\n        Build the image using docker buildx\n```\n\n***\n\n## Pulling the libraries from Docker Hub\n\nIf you don't want to build everything from scratch (it takes quite a while to\ncompile everything), you can download the pre-built version from [**Docker Hub**](https://hub.docker.com/r/tttapa/)\nusing the `--pull` option of the `build.sh` script in the [`docker-arm-cross-build-scripts` folder](https://github.com/tttapa/docker-arm-cross-build-scripts/blob/main).\nFor example:\n\n```sh\n./docker-arm-cross-build-scripts/build.sh rpi3-aarch64 --pull --export\n```\n\n## Building everything yourself\n\nTo build everything yourself, you can just run the `build.sh` without the\n`--pull` option:\n\n```sh\n./docker-arm-cross-build-scripts/build.sh rpi3-aarch64 --export\n```\n\n## Details\n\n### The cross-compilation toolchain\n\nCrosstool-NG is used to build a modern GCC toolchain that runs on your computer\nor in a Docker container, and that generates binaries for the Raspberry Pi.\nThis is much faster than compiling everything on the Pi itself.\n\nThe toolchain used to be built by scripts in this repository, but have since\nbeen moved to their own repository, [**tttapa/docker-arm-cross-toolchain**](https://github.com/tttapa/docker-arm-cross-toolchain).\n\nYou can download them directly from the [Releases page](https://github.com/tttapa/docker-arm-cross-toolchain/releases)\n\n### Cross-compiling the necessary libraries\n\nThe toolchain is then used to compile all libraries for the Raspberry Pi. This \nis what the `docker-arm-cross-build-scripts/build.sh` script takes care of.\n\nThese libraries are installed in two locations:\n1. in the **“sysroot”**: this is a folder where all system files and libraries\n   are installed that are required for the build process of other libraries\n2. in the **“staging area”**: this is the folder that will be copied to the SD\n   card of the Raspberry Pi later. It contains the libraries that we built, but\n   not the system files (because those are already part of the Ubuntu/Raspbian\n   installation of the Pi).\n\nEverything is installed in `/usr/local/`, so it shouldn't interfere with the software installed by your package manager.\n[`userland`](https://github.com/raspberrypi/userland) is an exception, it's installed in `/opt/vc/`.\n\nIf you just want to know how to cross-compile a specific package, have a look at the scripts in the\n[`docker-arm-cross-build-scripts/cross-build/install-scripts`](https://github.com/tttapa/docker-arm-cross-build-scripts/blob/main/cross-build/install-scripts)\nfolder.  \n\n### Exporting the toolchain, sysroot and staging area\n\nOnce all components have been built, they have to be extracted from the Docker\nbuild containers, and installed to the correct locations.  \nYou can extract everything using the `--extract` option of the `build.sh` script.\n\nTo test the newly cross-compiled binaries, just extract the contents of the\nright `staging-rpix-xxx-linux-gnuxxx.tar` archive to the root folder of the\nRaspberry Pi:\n\n**Do NOT extract the staging area to the root directory of your computer, you will destroy your system!**\n```sh\n# Copy the staging area archive to the Pi\n# This command may take a while, depending on the speed of your SD card\nscp ./docker-arm-cross-build-scripts/staging-rpi3-aarch64.tar RPi3:/tmp\n# Install everything to the root of the filesystem\n# (will only install to /usr/local and /opt)\n# Enter the sudo password of the Pi if necessary\n# This command may take a while, depending on the speed of your SD card\nssh -t RPi3 \"sudo tar xf /tmp/staging-rpi3-aarch64.tar -C / --strip-components=1\"\n# Configure dynamic linker run-time bindings so newly installed libraries\n# are found by the linker\n# Enter the sudo password of the Pi if necessary\nssh -t RPi3 \"sudo ldconfig\"\n```\n\n## Building the example project\n\nYou have to tell CMake to use the new toolchain with the correct “sysroot”\ndirectory. This is done through the CMake Toolchain files in the `cmake`\nfolder of this repository.\n\nI highly recommend using the [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools)\nextension in Visual Studio Code. \nThe cross-compilation toolchain kits are defined in `.vscode/cmake-kits.json`.\nTo select one, hit `CTRL+Shift+P` and type `CMake: Select a Kit` and then select\nthe right `Raspberry Pi` kit for your architecture.\nIt'll configure the CMake project for you, and then you can build everything by\nclicking the “Build” button in the blue toolbar at the bottom of the window.\n\nYou can of course also configure and build the project manually, without VSCode:\n\n```sh\ncmake -Bbuild -S. \\\n    -DCMAKE_TOOLCHAIN_FILE=../cmake/aarch64-rpi3-linux-gnu.cmake \\\n    -DCMAKE_BUILD_TYPE=Debug\ncmake --build build -j\n```\n\nThe binaries will be in the `build` folder, and you can copy them to the Raspberry Pi over SSH using `scp` for example.\n\n### Debugging\n\nDuring development, it's best to compile everything for your computer first\n(using a native compiler you have installed on your system instead of the\ntoolchain we built earlier).\nThis makes it very easy to debug your code because you can run the code locally.\n\nThe CMake Tools extension makes debugging very easy, just click the bug icon in\nthe blue toolbar at the bottom of the window and select the target to debug.\n\nA useful feature of this repository is that it allows you to debug on-target as\nwell: the GUI for the debugger runs on your computer, but the actual code runs\non the Raspberry Pi. This uses SSH and the GDB server.\n\nCheck out the `.vscode/launch.json` and `.vscode/tasks.json` files to see how it\nworks: first, the active target binary is copied to the Raspberry Pi over SSH,\nthe GDB server is started on the RPi, and the local GDB client connects to it.\n\nThis requires the right SSH and hostname setup, both on your computer and on the\nRPi. Instructions can be found here: \u003chttps://tttapa.github.io/Pages/Raspberry-Pi/Installation+Setup/index.html\u003e  \nMake sure mDNS is set up correctly, and that you have a `.ssh/config` file with\na config for the Raspberry Pi, called `RPi`, so that it matches the name \nspecified in the `.vscode/launch.json` and `.vscode/tasks.json` files.\n\n## Cross-compiling Python modules and C/C++ and Cython extensions\n\nThe [`extra/python/cross-compile-module`](extra/python/cross-compile-module)\nfolder contains small guides explaining how to cross-compile Python and Cython\nmodules for the Raspberry Pi.\n\n- [`extra/python/cross-compile-module/spam`](extra/python/cross-compile-module/spam)\n  builds the classic [Spam example](https://docs.python.org/3/extending/extending.html)\n  by manually invoking the compiler, as a very simple introduction.\n- [`extra/python/cross-compile-module/cython`](extra/python/cross-compile-module/cython)\n  compiles a Cython module, with a very minimal `setup.py` script.\n- [`extra/python/cross-compile-module/py-build-cmake`](extra/python/cross-compile-module/py-build-cmake)\n  cross-compiles a full-fledged, real-world Python package, using the [py-build-cmake](https://github.com/tttapa/py-build-cmake)\n  build backend, which supports cross-compilation out of the box.\n\nFor serious projects, using [py-build-cmake](https://github.com/tttapa/py-build-cmake)\nand [pybind11](https://github.com/pybind/pybind11) is recommended.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftttapa%2Frpi-cpp-toolchain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftttapa%2Frpi-cpp-toolchain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftttapa%2Frpi-cpp-toolchain/lists"}