raspberry:cross-platform-compile:cross-platform-debugging
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| raspberry:cross-platform-compile:cross-platform-debugging [2026/09/04 07:32] – created - external edit 127.0.0.1 | raspberry:cross-platform-compile:cross-platform-debugging [2026/09/04 07:34] (current) – [Links] oscar | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Cross Platform | + | ====== Cross Platform |
| - | --- | + | |
| - | This page describes how to setup a cross platform build environment where the Debian distribution and version on build host and run-time Raspberry are identical. It will install and use the same ARM libraries (libc) and header version for building the armhf binary. | + | |
| - | I have used 2 different approaches to setup a cross build environment: | + | |
| - | - Debian Crossbuild packages | + | |
| - | - Manual setup | + | |
| - | Debian' | + | |
| - | ===== GCC and Linux Architectures ===== | + | |
| - | GCC is also used to cross compile Linux applications. Applications can be compiled for 32-bit or 64-bit Linux systems. | + | |
| - | ^Architecture^Compilers^ | + | |
| - | |32-bit|arm-linux-gnueabihf-gcc \\ arm-linux-gnueabihf-g++| | + | |
| - | |64-bit|aarch64-linux-gnu-gcc \\ aarch64-linux-gnu-g++| | + | |
| - | Check the current target architecture by logging into the Pi: | + | |
| - | To check if system is running a 32 (Raspberry) or 64 (X86) architecture, | + | |
| - | < | + | |
| - | # getconf LONG_BIT | + | |
| - | ------------------ | + | |
| - | 32 | + | |
| - | + | ||
| - | file / | + | |
| - | ------------------------- | + | |
| - | / | + | |
| - | </ | + | |
| - | ===== Method 1: Debian Crossbuild packages ===== | + | |
| - | === Build tools === | + | |
| - | Install all the required build tools on the Debian x86-64 host: | + | |
| - | < | + | |
| - | # apt-get update | + | |
| - | # apt-get upgrade | + | |
| - | # apt-get install build-essential | + | |
| - | # apt-get install crossbuild-essential-armhf | + | |
| - | </ | + | |
| - | `crossbuild-essential-armhf` installs the ARM cross C/C++ compiler and its | + | |
| - | basic runtime support. It does not install arbitrary target libraries such as | + | |
| - | OpenSSL, curl or ALSA development files. | + | |
| - | + | ||
| - | === multiarch mechanism === | + | |
| - | To setup dpkg for the armhf architecture run the `dpkg --add-architecture armhf` command. That command is needed when installing `:armhf` packages into the host's normal APT-managed filesystem. | + | |
| - | To setup dpkg for armhf architecture: | + | |
| - | < | + | |
| - | dpkg --add-architecture armhf | + | |
| - | apt-get update | + | |
| - | </ | + | |
| - | This enables Debian' | + | |
| - | `, while retaining `libfoo-dev: | + | |
| - | For example: | + | |
| - | < | + | |
| - | / | + | |
| - | / | + | |
| - | + | ||
| - | / | + | |
| - | / | + | |
| - | </ | + | |
| - | + | ||
| - | + | ||
| - | === Additional Libraries === | + | |
| - | The standard `clib` libraries are already installed with the `crossbuild-essential-armhf` essential package. Installing additional development libraries for the new arhitecture: | + | |
| - | < | + | |
| - | apt-get install libssl-dev: | + | |
| - | apt-get install gnutls-dev: | + | |
| - | apt-get install libmicrohttpd-dev: | + | |
| - | apt-get install libgpiod-dev: | + | |
| - | </ | + | |
| - | This gives you a reasonably complete Debian cross-development environment looking like this: | + | |
| - | < | + | |
| - | x86-64 Debian | + | |
| - | │ | + | |
| - | ├── native build tools | + | |
| - | │ | + | |
| - | ├── arm-linux-gnueabihf-gcc | + | |
| - | │ | + | |
| - | ├── ARM binutils | + | |
| - | │ | + | |
| - | ├── ARM libc development files | + | |
| - | │ | + | |
| - | └── ARM headers/ | + | |
| - | │ | + | |
| - | ▼ | + | |
| - | Raspberry Pi armhf | + | |
| - | </ | + | |
| - | ===== Method 2: Manual Setup ===== | + | |
| - | ==== Set Up Cross Build Tools ==== | + | |
| - | The first step is to install the development tools on the desktop, or host system. From the command line run the following: | + | |
| - | < | + | |
| - | # apt-get update | + | |
| - | # apt-get upgrade | + | |
| - | # apt-get install build-essential | + | |
| - | # apt-get install gcc-arm-linux-gnueabihf | + | |
| - | # apt-get install g++-arm-linux-gnueabihf | + | |
| - | # apt-get install gcc-aarch64-linux-gnu | + | |
| - | # apt-get install g++-aarch64-linux-gnu | + | |
| - | </ | + | |
| - | The first line makes sure that the system is up to date. The second instruction installs the general build tools. The third installs the C and C++ compiler and build tools for the Pi’s ARM processor. The ARM architecture designation, | + | |
| - | < | + | |
| - | arm-linux-gnueabihf-g++ -v | + | |
| - | </ | + | |
| - | ==== Get required ARM libraries ==== | + | |
| - | Depending on the application and required libraries, it is possible that not all libraries are available. Easiest way is to copy these over from an existing Raspberry installation. | + | |
| - | On the Raspberry these are available in: // | + | |
| - | < | + | |
| - | mkdir / | + | |
| - | scp root@192.168.178.xx:/ | + | |
| - | </ | + | |
| - | Now we need to tell the loader (ld) to look for libraries in this extra directory | + | |
| - | < | + | |
| - | nano / | + | |
| - | Insert the path "/ | + | |
| - | ldconfig | + | |
| - | </ | + | |
| - | ==== Test Application ==== | + | |
| - | The host system should now be ready to build a Raspberry Pi program. Let’s test it with a minimal test application, | + | |
| - | + | ||
| - | < | + | |
| - | #include < | + | |
| - | using namespace std; | + | |
| - | + | ||
| - | int main() | + | |
| - | { | + | |
| - | cout << "This is our first test!" << endl; | + | |
| - | return 0; | + | |
| - | } | + | |
| - | </ | + | |
| - | Build the program. The first line compiles the file test.cpp and the second links the compiler output to build the executable. | + | |
| - | < | + | |
| - | arm-linux-gnueabihf-g++ -O3 -g3 -Wall -c -fPIC -o test.o test.cpp | + | |
| - | arm-linux-gnueabihf-g++ -o test test.o | + | |
| - | </ | + | |
| - | Now let's check the architecture of the executable with the ' | + | |
| - | < | + | |
| - | file test | + | |
| - | test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, | + | |
| - | interpreter / | + | |
| - | BuildID[sha1]=3a73dacec4a89fa2c6ea9751d18743ba9bba33ac, | + | |
| - | + | ||
| - | scp test pi@192.168.178.xx:/ | + | |
| - | </ | + | |
| - | + | ||
| - | That's all. I told you this was simple. | + | |
| - | + | ||
| - | ===== Remote Debugging | + | |
| We will gdb on host and Pi to debug with the GCC toolset. First install the debug capability on our desktop system that works with target systems regardless of the processor architecture. | We will gdb on host and Pi to debug with the GCC toolset. First install the debug capability on our desktop system that works with target systems regardless of the processor architecture. | ||
| < | < | ||
| Line 184: | Line 45: | ||
| The debugger provides a large number of commands for manipulating breakpoints, | The debugger provides a large number of commands for manipulating breakpoints, | ||
| - | ====== Links ====== | + | |
| - | * https:// | + | |
| - | * https:// | + | |
| - | * https:// | + | |
| - | * https:// | + | |
| - | * https:// | + | |
| - | * https:// | + | |
| - | * https:// | + | |
raspberry/cross-platform-compile/cross-platform-debugging.1788507162.txt.gz · Last modified: by 127.0.0.1
