如何让CMake find_package找到并使用PkgConfig进行交叉编译

问题描述 投票:0回答:1

我正在尝试交叉编译 Beaglebone black 的应用程序。

我已在 Beaglebone 上直接成功编译了应用程序,同时注释掉了下面 CMakeLists.txt 中的交叉编译相关部分。 我还交叉编译了本教程中的

hello
程序:https://github.com/robamu-org/beaglebone-crosscompiling/tree/main

所以我的目标是结合教程中的交叉编译方法以及这里的见解:pkg-config 无法在 sysroot 目录下找到包

为了让 CMake 与 pkg-config 和 GTKMM 正确交叉编译。

这是我的CMakeLists.txt

cmake_minimum_required(VERSION 3.13)

#  ~~~~~~~~~~~ CROSS COMPILE SECTION (commented out on successful beaglebone build)~~~~

set(CMAKE_TOOLCHAIN_FILE "BBBToolchain.cmake")

set(CMAKE_SYSROOT "/home/cole/beaglebone/cross-compiler-toolchain/linaro-toolchain/rootfs")
set(ENV{PKG_CONFIG_DIR} "/home/cole/beaglebone/cross-compiler-toolchain/linaro-toolchain/rootfs/usr/bin")
set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig")
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})

# ~~~~ CROSS COMPILE SECTION END

project(question-manager CXX)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GTKMM REQUIRED gtkmm-3.0)

add_executable(EMBEDDED-GUI src/view/embedded-app/opengtk-version/start-gui.cpp
                            src/view/embedded-app/opengtk-version/main-window.cpp
                            src/view/embedded-app/opengtk-version/question-card.cpp)

target_link_libraries(EMBEDDED-GUI PUBLIC ${GTKMM_LIBRARIES})
target_include_directories(EMBEDDED-GUI PUBLIC ${GTKMM_INCLUDE_DIRS})
target_link_directories(EMBEDDED-GUI PUBLIC ${GTKMM_LIBRARY_DIRS})
target_compile_options(EMBEDDED-GUI PUBLIC ${GTKMM_CFLAGS_OTHER})

但是,当我尝试配置 CMake 时,它仍然使用 Host PkgConfig (我的主机版本是“0.29.2”,而目标版本是“0.29”

$ cmake ..
-- Beagle Bone Black sysroot: /home/scshafe/beaglebone/cross-compiler-toolchain/linaro-toolchain/rootfs
-- No CROSS_COMPILE environmental variable set, using default ARM linux cross compiler name arm-linux-gnueabihf
-- Using sysroot path: /home/scshafe/beaglebone/cross-compiler-toolchain/linaro-toolchain/rootfs
-- Beagle Bone Black sysroot: /home/scshafe/beaglebone/cross-compiler-toolchain/linaro-toolchain/rootfs
-- No CROSS_COMPILE environmental variable set, using default ARM linux cross compiler name arm-linux-gnueabihf
-- Using sysroot path: /home/scshafe/beaglebone/cross-compiler-toolchain/linaro-toolchain/rootfs
-- The CXX compiler identification is GNU 7.5.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/scshafe/beaglebone/cross-compiler-toolchain/linaro-toolchain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2") 
-- Checking for module 'gtkmm-3.0'
--   No package 'gtkmm-3.0' found
CMake Error at /usr/share/cmake-3.22/Modules/FindPkgConfig.cmake:603 (message):
  A required package was not found
Call Stack (most recent call first):
  /usr/share/cmake-3.22/Modules/FindPkgConfig.cmake:825 (_pkg_check_modules_internal)
  CMakeLists.txt:48 (pkg_check_modules)


-- Configuring incomplete, errors occurred!
See also "/home/scshafe/git-projects/question-list-manager/build/CMakeFiles/CMakeOutput.log".

如果我添加

set(ENV{PKG_CONFIG_PATH} "/home/scshafe/beaglebone/cross-compiler-toolchain/linaro-toolchain/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig")

PkgConfig 会找到 gtkmm-3.0,但它仍然使用“0.29.2”主机版本,最终我在尝试构建时遇到链接错误。

gcc cmake cross-compiling pkg-config
1个回答
0
投票

请使用

PKG_CONFIG_LIBDIR
来代替。

© www.soinside.com 2019 - 2024. All rights reserved.