User Tools

Site Tools


raspberry:raspberry-cross-platform

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:raspberry-cross-platform [2024/04/24 16:39] – [NEW] oscarraspberry:raspberry-cross-platform [2024/09/15 07:12] (current) – [Cross Platform Development for Raspberry] oscar
Line 1: Line 1:
 ====== Cross Platform Development for Raspberry ====== ====== Cross Platform Development for Raspberry ======
-Cross-development means developing and compiling programs on another platform then it intended to run upon. It is a common approach for Pi, since it’s also how Raspian is built. For quite some time I did compile Pi applications on the Pi itself. Which works quite well, but has one large drawback: performance. Being able to compile these programs on my 8 core 16GB desktop, improved compilation time enorms. And it is quite simple. Let's have a look! +Cross-development means developing and compiling programs on another platform then it intended to run upon. It is a common approach for Pi, since it’s also how Raspian is built. For quite some time I did compile Pi applications on the Pi itself. Which works quite well, but has one large drawback: performance. Being able to compile these programs on my 8 core 16GB desktop, improved compilation time enorms. And it is quite simple. I have used 2 different approaches to setup a cross build environment: 
-===== Set Up Cross Build Tools ===== +  - Manual setup **<- Used by me** 
-I’m using Ubuntu 16.04 on my desktop, but this should work with all Debian derivativesBe carefull with older  distribution since the ARM development libraries may not be the ones used on the PiThe first step is to install the development tools on the desktop, or host systemFrom the command line run the following:+  - Debian Crossbuild packages 
 +Let's have a look! 
 + 
 +===== GCC and Linux Architectures ===== 
 +GCC is also used to cross compile Linux applicationsApplications can be compiled for 32-bit or 64-bit Linux systems. 
 +  * For 32-bit:  
 +    * arm-linux-gnueabihf-gcc and  
 +    * arm-linux-gnueabihf-g++. 
 +  * For 64-bit:  
 +    * aarch64-linux-gnu-gcc and  
 +    * aarch64-linux-gnu-g++. 
 +Check the current target architecture by logging into the Pi:
 <code> <code>
-sudo apt-get updateapt-get upgrade +# gcc -dumpmachine 
-sudo apt-get install build-essential +------------------ 
-sudo apt-get install g++-arm-linux-gnueabihf+arm-linux-gnueabihf 
 +</code> 
 + 
 +===== Method 1: Debian Crossbuild packages ===== 
 +==== Required Development sources  ==== 
 +Install all the required build tools: 
 +<code> 
 +apt-get update 
 +apt-get upgrade 
 +# apt-get install crossbuild-essential-armhf 
 +</code> 
 +Setup dpkg for armhf architecture: 
 +  dpkg --add-architecture armhf 
 +  apt-get update 
 +Installing the development libraries for new arhitecture: 
 +  apt-get install libssl-dev:armhf 
 +  apt-get install gnutls-dev:armhf 
 +  apt-get install libmicrohttpd-dev:armhf 
 +  apt-get install libgpiod-dev: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: 
 +<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> </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 dash 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:+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> <code>
 arm-linux-gnueabihf-g++ -v arm-linux-gnueabihf-g++ -v
 </code> </code>
-===== Get required ARM libraries =====+==== 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.  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). 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).
Line 25: Line 65:
 ldconfig ldconfig
 </code> </code>
-===== Test Application =====+==== 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: 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:
   
Line 55: Line 95:
 That's all. I told you this was simple. That's all. I told you this was simple.
  
-====== Remote Debugging ======+===== 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. 
 <code> <code>
Line 100: Line 140:
  
 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. 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.
- 
- 
- 
-====== NEW ====== 
-Check the current target architecture by logging into the Pi: 
-<code> 
-# gcc -dumpmachine 
------------------- 
-arm-linux-gnueabihf 
-</code> 
  
 ====== Links ====== ====== Links ======
Line 116: Line 146:
   * https://jensd.be/1126/linux/cross-compiling-for-arm-or-aarch64-on-debian-or-ubuntu   * https://jensd.be/1126/linux/cross-compiling-for-arm-or-aarch64-on-debian-or-ubuntu
   * https://learn.arm.com/install-guides/gcc/cross/   * 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 
-$ sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu+  * https://prashanth.entertolearn.in/debian-arm-architecture-and-emulation/using-debian-arm-cross-compiler-for-bare-metal-programming
raspberry/raspberry-cross-platform.1713976748.txt.gz · Last modified: by oscar