I want to cross-compile application on my Debian 12 (WSL) host machine. When I do it on Ubuntu 24.04 (WSL), it's all right, but CMAKE on Debian cannot find xkbcommon-x11
, which is present in Cmake since 3.18. I have written a simple script that looks for this library and outputs version of found xkbcommon-x11
:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.18)
project(Test)
find_package(PkgConfig QUIET)
# pkg_check_modules(XKB_COMMON_X11 IMPORTED_TARGET "xkbcommon-x11>=0.4.1")
pkg_check_modules(XKB_COMMON_X11 IMPORTED_TARGET "xkbcommon-x11")
if (NOT TARGET PkgConfig::XKB_COMMON_X11)
set(XKB_COMMON_X11_FOUND 0)
endif()
message("XKB_COMMON_X11_FOUND: ${XKB_COMMON_X11_FOUND}")
message("XKB_COMMON_X11_VERSION: ${XKB_COMMON_X11_VERSION}")
toolchain.cmake:
cmake_minimum_required(VERSION 3.18)
include_guard(GLOBAL)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
IF(NOT DEFINED ENV{sroot})
message(FATAL_ERROR "Please set the environment variable sroot to the path of the sysroot")
ENDIF()
IF (NOT EXISTS $ENV{sroot}/usr/include)
message(FATAL_ERROR "It seems that the sysroot image is not mounted. Please mount it first.")
ENDIF()
set(TARGET_SYSROOT $ENV{sroot})
set(CMAKE_SYSROOT ${TARGET_SYSROOT})
set(ENV{PKG_CONFIG_PATH} $PKG_CONFIG_PATH:/usr/lib/aarch64-linux-gnu/pkgconfig)
set(ENV{PKG_CONFIG_LIBDIR} /usr/lib/pkgconfig:/usr/share/pkgconfig/:${TARGET_SYSROOT}/usr/lib/aarch64-linux-gnu/pkgconfig:${TARGET_SYSROOT}/usr/lib/pkgconfig)
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})
# if you use other version of gcc and g++ than gcc/g++ 9, you must change the following variables
set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc-12)
set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++-12)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem=/usr/include -isystem=/usr/include/aarch64-linux-gnu")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_BUILD_RPATH ${TARGET_SYSROOT})
The script is run like this:
cmake . --toolchain toolchain.cmake
Both Ubuntu and Debian builds use same sysroot, so it cannot be problem of sysroot. Both Ubuntu and Debian builds use same version of CMake: 3.28.3.
The output for Ubuntu is:
-- The C compiler identification is GNU 12.3.0
-- The CXX compiler identification is GNU 12.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc-12 - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/aarch64-linux-gnu-g++-12 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Checking for module 'xkbcommon-x11'
-- Found xkbcommon-x11, version 1.5.0
XKB_COMMON_X11_FOUND: 1
XKB_COMMON_X11_VERSION: 1.5.0
-- Configuring done (7.7s)
-- Generating done (0.0s)
The output for Debian is:
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc-12 - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/aarch64-linux-gnu-g++-12 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
XKB_COMMON_X11_FOUND: 0
XKB_COMMON_X11_VERSION:
-- Configuring done
-- Generating done
Why Debian cannot find this library? How can I correct it?
UPD
On Ubuntu, I've output for target properties, and it refers to libraries installed in sysroot:
PkgConfig::XKB_COMMON_X11 INTERFACE_LINK_LIBRARIES = /home/a/buildimg/root/usr/lib/aarch64-linux-gnu/libxkbcommon-x11.so;/home/a/buildimg/root/usr/lib/aarch64-linux-gnu/libxkbcommon.so