raspberry:cross-platform-compile:setup-for-identical-debian-versions
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| raspberry:cross-platform-compile:setup-for-identical-debian-versions [2026/09/04 06:41] – [GCC and Linux Architectures] oscar | raspberry:cross-platform-compile:setup-for-identical-debian-versions [2026/09/04 12:39] (current) – oscar | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Cross Platform Development for Raspberry | + | ====== Cross Platform Development for identical distributions |
| --- | --- | ||
| - | 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. | + | 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: | I have used 2 different approaches to setup a cross build environment: | ||
| - | - Manual setup **<- Used by me** | ||
| - Debian Crossbuild packages | - Debian Crossbuild packages | ||
| - | Let' | + | - Manual setup |
| + | Debian' | ||
| - | ===== GCC and Linux Architectures ===== | + | ==== Architecture |
| GCC is also used to cross compile Linux applications. Applications can be compiled for 32-bit or 64-bit Linux systems. | GCC is also used to cross compile Linux applications. Applications can be compiled for 32-bit or 64-bit Linux systems. | ||
| ^Architecture^Compilers^ | ^Architecture^Compilers^ | ||
| |32-bit|arm-linux-gnueabihf-gcc \\ arm-linux-gnueabihf-g++| | |32-bit|arm-linux-gnueabihf-gcc \\ arm-linux-gnueabihf-g++| | ||
| |64-bit|aarch64-linux-gnu-gcc \\ aarch64-linux-gnu-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 ===== | ===== Method 1: Debian Crossbuild packages ===== | ||
| - | ==== Required Development sources | + | === Build tools === |
| - | Install all the required build tools: | + | Install all the required build tools on the Debian x86-64 host: |
| < | < | ||
| # apt-get update | # apt-get update | ||
| # apt-get upgrade | # apt-get upgrade | ||
| + | # apt-get install build-essential | ||
| # apt-get install crossbuild-essential-armhf | # apt-get install crossbuild-essential-armhf | ||
| </ | </ | ||
| - | Setup dpkg for armhf architecture: | + | `build-essential` is for building **native x86-64 programs**.`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 | dpkg --add-architecture armhf | ||
| apt-get update | apt-get update | ||
| - | Installing | + | </ |
| + | 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 | ||
| + | < | ||
| apt-get install libssl-dev: | apt-get install libssl-dev: | ||
| apt-get install gnutls-dev: | apt-get install gnutls-dev: | ||
| apt-get install libmicrohttpd-dev: | apt-get install libmicrohttpd-dev: | ||
| apt-get install libgpiod-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 ===== | ===== Method 2: Manual Setup ===== | ||
| ==== Set Up Cross Build Tools ==== | ==== Set Up Cross Build Tools ==== | ||
| Line 97: | Line 125: | ||
| </ | </ | ||
| - | 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. | ||
| - | < | ||
| - | sudo apt-get install gdb-multiarch | ||
| - | </ | ||
| - | Now install a debug server on the Pi system that can be connected to from our desktop and control execution on the target. | ||
| - | < | ||
| - | sudo apt-get install gdbserver | ||
| - | </ | ||
| - | |||
| - | Start the server on the Pi. The command starts the server, runs it continuously. The third parameter is the computer name or IP address of the host computer. In my case it is " | ||
| - | < | ||
| - | gdbserver --multi 192.168.178.18: | ||
| - | </ | ||
| - | The server uses stdout to display error messages and the output from the debugged program. | ||
| - | |||
| - | |||
| - | The program gdb-multiarch is an interactive program. On the host, enter the command: | ||
| - | < | ||
| - | gdb-multiarch | ||
| - | </ | ||
| - | |||
| - | This prints a lot of output followed by the prompt (gdb). You might want to add the quiet option (-q) to the command line. At the prompt, using the name of your Pi, enter the following commands and you should see the responses, as shown in italics here: | ||
| - | |||
| - | < | ||
| - | target extended-remote 192.168.178.61: | ||
| - | Remote debugging using 192.168.178.61: | ||
| - | set remote exec-file remote/test | ||
| - | [[no response]] | ||
| - | file test | ||
| - | Reading symbols from test...done. | ||
| - | </ | ||
| - | |||
| - | The target command tells gdb the name of the target system, 192.168.178.61 with port, 2001. If it worked, you’ll get the response shown; otherwise a timeout message. The set remote line specifies the file location to use on the Pi target system. Remember that the executable needs to be copied onto the target system every time it is changed. We’ll see how to do that from within gdb, below. The last command, file, is the path and filename on the host computer. This can be a directory other than where the debugger is running. Now, type the following and get the response as shown: | ||
| - | |||
| - | < | ||
| - | run | ||
| - | Starting program: /tmp/hello | ||
| - | [[ a bunch more lines, some warnings and stuff to ignore for now ]] | ||
| - | [Inferior 1 (process 234) exited normally] | ||
| - | </ | ||
| - | |||
| - | If it works you’ll see that last line. Now switch to the SSH terminal connected to the Pi and you’ll see a couple of lines of status, the output from the program, a blank line, and a line reporting the exit status of the program. If all this doesn’t work check the error message from the server. It should explain what is happening. Often there is a mismatch between what you told gdb and the location of the executable. | ||
| - | |||
| - | The debugger provides a large number of commands for manipulating breakpoints, | ||
| - | |||
| - | ====== Links ====== | ||
| - | * https:// | ||
| - | * https:// | ||
| - | * https:// | ||
| - | * https:// | ||
| - | * https:// | ||
| - | * https:// | ||
| - | * https:// | ||
raspberry/cross-platform-compile/setup-for-identical-debian-versions.1788504113.txt.gz · Last modified: by oscar
