User Tools

Site Tools


raspberry:cross-platform-compile:setup-for-identical-debian-versions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
raspberry:cross-platform-compile:setup-for-identical-debian-versions [2026/09/04 06:28] – oscarraspberry: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's have a look!+  - Manual setup 
 +Debian's own cross-compilation documentation recommends `crossbuild-essential-<architecture>` as the normal way of installing the cross compiler.
  
-===== 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.
-  * For 32-bit:  +^Architecture^Compilers^ 
-    * arm-linux-gnueabihf-gcc and  +|32-bit|arm-linux-gnueabihf-gcc \\ arm-linux-gnueabihf-g++| 
-    * arm-linux-gnueabihf-g++. +|64-bit|aarch64-linux-gnu-gcc \\ aarch64-linux-gnu-g++|
-  * For 64-bit:  +
-    * aarch64-linux-gnu-gcc and  +
-    * aarch64-linux-gnu-g++. +
-Check the current target architecture by logging into the Pi: +
-<code> +
-# gcc -dumpmachine +
------------------- +
-arm-linux-gnueabihf +
-</code> +
 ===== 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:
 <code> <code>
 # 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
 </code> </code>
-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: 
 +<code>
   dpkg --add-architecture armhf   dpkg --add-architecture armhf
   apt-get update   apt-get update
-Installing the development libraries for new arhitecture:+</code> 
 +This enables Debian's **multiarch** mechanism. You can then install ARM libraries alongside your normal x86 libraries by `apt install libfoo-dev:armhf 
 +`, while retaining `libfoo-dev:amd64` on the same machine. Debian's cross-toolchains are specifically designed to work with these multiarch library/header locations. The ARM compiler knows where to find the ARM versions. 
 +For example: 
 +<code> 
 +/usr/lib/x86_64-linux-gnu/ 
 +/usr/include/... 
 + 
 +/usr/lib/arm-linux-gnueabihf/ 
 +/usr/include/... 
 +</code> 
 + 
 + 
 +=== Additional Libraries === 
 +The standard `clib` libraries are already installed with the `crossbuild-essential-armhf` essential package. Installing additional development libraries and include files for the new arhitecture: 
 +<code>
   apt-get install libssl-dev:armhf   apt-get install libssl-dev:armhf
   apt-get install gnutls-dev:armhf   apt-get install gnutls-dev:armhf
   apt-get install libmicrohttpd-dev:armhf   apt-get install libmicrohttpd-dev:armhf
   apt-get install libgpiod-dev:armhf   apt-get install libgpiod-dev:armhf
 +</code>
 +This gives you a reasonably complete Debian cross-development environment looking like this:
 +<code>
 +x86-64 Debian
 +        │
 +        ├── native build tools
 +        │
 +        ├── arm-linux-gnueabihf-gcc
 +        │
 +        ├── ARM binutils
 +        │
 +        ├── ARM libc development files
 +        │
 +        └── ARM headers/libraries
 +                │
 +                ▼
 +          Raspberry Pi armhf
 +</code>
 ===== Method 2: Manual Setup ===== ===== Method 2: Manual Setup =====
 ==== Set Up Cross Build Tools ==== ==== Set Up Cross Build Tools ====
Line 96: Line 125:
 </code> </code>
  
-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.  
-<code> 
-sudo apt-get install gdb-multiarch 
-</code> 
-Now install a debug server on the Pi system that can be connected to from our desktop and control execution on the target.  
-<code> 
-sudo apt-get install gdbserver 
-</code> 
- 
-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 "192.168.178.18". 2001 is the port that the host and target will use for communication. Be aware that running the gdbserver is a potential security hole on the Pi. So make sure it can only be accessed from your local network. 
-<code> 
-gdbserver --multi 192.168.178.18:2001 
-</code> 
-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: 
-<code> 
-gdb-multiarch 
-</code> 
- 
-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: 
- 
-<code> 
-target extended-remote 192.168.178.61:2001 
-Remote debugging using 192.168.178.61:2001 
-set remote exec-file remote/test 
-[[no response]] 
-file test 
-Reading symbols from test...done. 
-</code> 
- 
-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: 
- 
-<code> 
-run 
-Starting program: /tmp/hello 
-[[ a bunch more lines, some warnings and stuff to ignore for now ]] 
-[Inferior 1 (process 234) exited normally] 
-</code> 
- 
-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, continuing execution, listing the program, etc. For instance, type in main and the program stops when main() is reached. A ‘c’ runs the program after a breakpoint. To help with debugging, there is an interesting mode, the Terminal User Interface, or tui. You can access and leave it by typing in Ctrl-x, Ctrl-a. This mode provides windows that show the source, registers, assembly language, and other information. 
- 
-====== Links ====== 
-  * https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads 
-  * https://www.acmesystems.it/arm9_toolchain 
-  * https://jensd.be/1126/linux/cross-compiling-for-arm-or-aarch64-on-debian-or-ubuntu 
-  * https://learn.arm.com/install-guides/gcc/cross/ 
-  * https://packages.debian.org/search?keywords=crossbuild-essential 
-  * https://www.get-edi.io/assets/pdfs/DebianCross.pdf 
-  * https://prashanth.entertolearn.in/debian-arm-architecture-and-emulation/using-debian-arm-cross-compiler-for-bare-metal-programming 
raspberry/cross-platform-compile/setup-for-identical-debian-versions.1788503321.txt.gz · Last modified: by oscar