I’m just getting started building an application in C++, and I want to cross-compile it for aarch64, which is the platform it’s going to run on. The target runs Ubuntu 18.04, and when my build laptop was running Ubuntu 18.04, the test worked fine – however, I generally run Ubuntu 22.04 on this laptop, and when moving the build there (everything else is the same!), it links the resulting binary against the wrong version of glibc.
I guess I don’t understand why the OS of the build host should matter here; I specified a rootfs directory where the target is installed (see my CMakeLists.txt
, below) – so why would it take anything from the build host? Certainly the actual version of glibc on the target root is correct…
Anyway, this is the CMakeLists.txt:
cmake_minimum_required(VERSION 3.21)
project(cross_test)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++)
set(CMAKE_FIND_ROOT_PATH /home/riz/testing/jetson_top_r32.7.2/Linux_for_Tegra/rootfs)
set(SOURCE_FILES
main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
…which, as I said, generates a working-on-aarch64 binary when run on an Ubuntu 18.04 laptop, but when run on a Ubuntu 22.04 one, the resulting binary gives problems:
linux:~$ /tmp/cross_test
/tmp/cross_test: /lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /tmp/cross_test)
What do I need to do to be able to target a different Ubuntu version as well as a different arch? To be clear, the directory in CMAKE_FIND_ROOT_PATH is the actual rootfs of the target machine.