Cross Compile for Raspberry Pi
ct-ng list-samples
ct-ng aarch64-rpi4-linux-gnu
- Log into the Raspberry Pi and check which libc version it is using:
ls /lib/aarch64-linux-gnu | grep libc-
Example Output:
libc-2.31.so
or
ldd --version
- Next check the kernel version:
uname -a
Example Output:
Linux raspberrypi 5.15.76-v8+ #1597 SMP PREEMPT Fri Nov 4 12:16:41 GMT 2022 aarch64 GNU/Linux
So the version is: 5.15
Configure this two versions with:
ct-ng menuconfig
unset LD_LIBRARY_PATH
ct-ng build
rsync -rl pi@<host>:{lib,usr} .
Toolchain-RaspberryPi.cmake
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
SET(TOOLCHAIN_ROOT $ENV{HOME}/x-tools/aarch64-rpi4-linux-gnu)
SET(CMAKE_C_COMPILER ${TOOLCHAIN_ROOT}/bin/aarch64-rpi4-linux-gnu-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_ROOT}/bin/aarch64-rpi4-linux-gnu-g++)
SET(CMAKE_SYSROOT ${TOOLCHAIN_ROOT}/aarch64-rpi4-linux-gnu/sysroot)
SET(PKG_CONFIG_EXECUTABLE "/usr/bin/pkg-config")
SET(ENV{PKG_CONFIG_DIR} "")
SET(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/lib/pkgconfig:${CMAKE_SYSROOT}/lib/aarch64-linux-gnu/pkgconfig:${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig:${CMAKE_SYSROOT}/usr/lib/aarch64-linux-gnu/pkgconfig:${CMAKE_SYSROOT}/usr/local/lib/pkgconfig")
SET(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})
SET(CMAKE_LIBRARY_ARCHITECTURE aarch64-linux-gnu)
SET(CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}")
# Search for programs that are executed during build
# only on the host system
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Do not search for libs, include dirs or
# packages on the host system
# Only search in paths defined by
# CMAKE_FIND_ROOT_PATH
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
Build:
cmake -DCMAKE_TOOLCHAIN_FILE="cmake/Toolchain-RaspberryPi.cmake" ..