Cross Compilation
A cross-compiler is a compilation tool that runs on a host platform (e.g., Ubuntu or a virtual machine) but generates executable files for a target platform (e.g., ARM, MIPS).Since development boards have limited resources, Buildroot does not support local compilation of C programs by default, so a cross-compilation toolchain is required. The cross-compiler is located in the directory:<SDK directory>/prebuilts/gcc/linux-x86/arm/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin.The following guide explains how to configure the cross-compiler to compile C programs.
1. Setting Up the Cross-Compilation Toolchain
Set the environment variable for the cross-compilation tool. To make this permanent, edit the configuration file (e.g.,
.bashrcor.profile):vim ~/.bashrcSet the environment variable for the cross-compilation tool. To make this permanent, edit the configuration file (e.g.,
.bashrcor.profile):export PATH=/home/ubuntu/luckfox-lyra-sdk/prebuilts/gcc/linux-x86/arm/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin:$PATH- Note: Replace the SDK path as per your setup.
Update the environment variables to apply the changes:
source ~/.bashrcCompile a program using the cross-compiler:
arm-none-linux-gnueabihf-gcc gpio.c -o gpioTransfer the executable file to the development board:
scp gpio root@192.168.10.103:/root- Note: Replace the IP address with your actual target's IP.
2. CMake
Create a
CMakeLists.txtfile:cmake_minimum_required(VERSION 3.10)
project(GpioProject)
set(CMAKE_C_COMPILER /home/ubuntu/luckfox-lyra-sdk/prebuilts/gcc/linux-x86/arm/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gcc)
add_executable(gpio gpio.c)Create a
buildfolder and navigate into it:mkdir build && cd buildCompile the program:
cmake ..
make