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
raspberry:cross-platform-compile:setup-for-identical-debian-versions [2026/09/04 12:39] – oscarraspberry:cross-platform-compile:setup-for-identical-debian-versions [2026/12/01 05:26] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-====== 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. 
-I have used 2 different approaches to setup a cross build environment: 
-  - Debian Crossbuild packages 
-  - Manual setup 
-Debian's own cross-compilation documentation recommends `crossbuild-essential-<architecture>` as the normal way of installing the cross compiler. 
- 
-==== Architecture ==== 
-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++| 
-===== Method 1: Debian Crossbuild packages ===== 
-=== Build tools === 
-Install all the required build tools on the Debian x86-64 host: 
-<code> 
-# apt-get update 
-# apt-get upgrade 
-# apt-get install build-essential 
-# apt-get install crossbuild-essential-armhf 
-</code> 
-`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 
-  apt-get update 
-</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 gnutls-dev:armhf 
-  apt-get install libmicrohttpd-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 ===== 
-==== 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: 
-<code>That will involve s 
-# 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 
-</code> 
-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-, is used as a prefix to distinguish the ARM tools from the host system tools. Note the dashThat will involve s at the end of the string. Test the installation by entering the commant below. This reports the version of the G++ compiler installed and other information: 
-<code> 
-arm-linux-gnueabihf-g++ -v 
-</code> 
-==== 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: //**/usr/lib/arm-linux-gnueabihf**//. On the target build environment the library path is: //**/usr/arm-linux-gnueabihf/lib/**//. We will be placing these retrieved libraries in a separate subdirectory (extra). 
-<code> 
-mkdir /usr/arm-linux-gnueabihf/lib/extra 
-scp root@192.168.178.xx:/usr/lib/arm-linux-gnueabihf/libxxxx.* /usr/arm-linux-gnueabihf/lib/extra 
-</code> 
-Now we need to tell the loader (ld) to look for libraries in this extra directory 
-<code> 
-nano /etc/ld.so.conf.d/arm-linux-gnueabihf.conf 
-Insert the path "/usr/arm-linux-gnueabihf/lib/extra" into this file. Then save and run: 
-ldconfig 
-</code> 
-==== Test Application ==== 
-The host system should now be ready to build a Raspberry Pi program. Let’s test it with a minimal test application, just to see if everything is working. Create the following test.cpp file: 
-  
-<code> 
-#include <iostream> 
-using namespace std; 
- 
-int main()  
-{ 
-  cout << "This is our first test!" << endl; 
-  return 0; 
-} 
-</code> 
-Build the program. The first line compiles the file test.cpp and the second links the compiler output to build the executable.  
-<code> 
-arm-linux-gnueabihf-g++ -O3 -g3 -Wall -c -fPIC -o test.o test.cpp 
-arm-linux-gnueabihf-g++ -o test test.o 
-</code> 
-Now let's check the architecture of the executable with the 'file' command. If this shows 'ARM'it is compiled for an ARM processor and can transfer it to the Pi. 
-<code> 
-file test 
-test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked,  
-interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, 
-BuildID[sha1]=3a73dacec4a89fa2c6ea9751d18743ba9bba33ac, not stripped 
- 
-scp test pi@192.168.178.xx:/tmp 
-</code> 
  
raspberry/cross-platform-compile/setup-for-identical-debian-versions.1788525558.txt.gz · Last modified: by oscar