Home >Backend Development >C++ >How to Configure Cross-Compilation for Raspberry Pi with a Pre-built Toolchain on Ubuntu?
This guide aims to assist you in installing and configuring the pre-built Raspbian toolchain on your Ubuntu host machine for cross-compiling for Raspberry Pi.
Clone the Repository: Enter the following command to clone the toolchain repository:
git clone git://github.com/raspberrypi/tools.git
Add to PATH: Open the ~/.bashrc file in a text editor and append the following line to add the toolchain to your PATH:
export PATH=$PATH:$HOME/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin
Verify Access: Refresh your terminal session by restarting it or executing . ~/.bashrc. Verify the compiler by typing:
arm-linux-gnueabihf-gcc -v
Copy Files from Raspberry Pi: Establish a connection to your Raspberry Pi via SSH. Copy the entire /lib and /usr directories from the Pi to your rootfs folder using the following command:
rsync -rl --delete-after --safe-links [email protected]:/{lib,usr} $HOME/raspberrypi/rootfs
Replace [email protected] with your Pi's IP address.
Create CMake Config File: Create a file named pi.cmake in ~/home/raspberrypi with the following content:
SET(CMAKE_SYSTEM_NAME Linux) SET(CMAKE_SYSTEM_VERSION 1) SET(CMAKE_C_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc) SET(CMAKE_CXX_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++) SET(CMAKE_FIND_ROOT_PATH $ENV{HOME}/raspberrypi/rootfs) SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
The above is the detailed content of How to Configure Cross-Compilation for Raspberry Pi with a Pre-built Toolchain on Ubuntu?. For more information, please follow other related articles on the PHP Chinese website!