微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试使用 qemu 交叉构建和打包项目并获得“导入的目标“PkgConfig::gst”包括不存在的路径”错误

如何解决尝试使用 qemu 交叉构建和打包项目并获得“导入的目标“PkgConfig::gst”包括不存在的路径”错误

我有一个项目,我正在尝试在 arm64 架构上构建。我在 Ubuntu 18.04 上,所以我使用 qemu 进行交叉构建。我正在使用以下说明来模拟 arm64 环境:

sudo apt-get install debootstrap qemu-user-static schroot
sudo qemu-debootstrap --arch=arm64 bionic arm64-ubuntu

echo "[arm64-ubuntu]
description=Ubuntu 16.04 Xenial (arm64)
directory=$(pwd)/arm64-ubuntu
root-users=$(whoami)
users=$(whoami)
type=directory" | sudo tee /etc/schroot/chroot.d/arm64-ubuntu

schroot -c arm64-ubuntu -u root

它可以工作,当我在模拟环境中时,我可以使用以下命令安装我需要的所有内容

add-apt-repository universe
add-apt-repository "deb http://ports.ubuntu.com/ubuntu-ports bionic-updates main universe"
apt update && apt full-upgrade

sudo apt install cmake pkg-config libglib2.0-dev libgstreamer1.0-dev libgstrtspserver-1.0-dev

再次,它工作正常,一切似乎都安装正常。但是当我运行时:

cmake ..

我收到以下错误

(arm64-ubuntu)root@me-mypc:/home/me/Projets/embedded/vespa/build# cmake ..
-- Configuring done
CMake Error in CMakeLists.txt:
  Imported target "PkgConfig::gst" includes non-existent path

    "/usr/lib/x86_64-linux-gnu/glib-2.0/include"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted,renamed,or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.



CMake Error in CMakeLists.txt:
  Imported target "PkgConfig::gst" includes non-existent path

    "/usr/lib/x86_64-linux-gnu/glib-2.0/include"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted,or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.



-- Generating done
-- Build files have been written to: /home/me/Projets/embedded/vespa/build

无论如何,文件已经构建好了,我仍然可以尝试制作包:

make package

但是我收到一个错误提示

(arm64-ubuntu)root@me-mypc-5590:/home/me/Projets/embedded/vespa/build# make package
Scanning dependencies of target vespa
[ 50%] Building C object CMakeFiles/vespa.dir/src/main.c.o
In file included from /usr/include/glib-2.0/glib/galloca.h:32:0,from /usr/include/glib-2.0/glib.h:30,from /usr/include/glib-2.0/gobject/gbinding.h:28,from /usr/include/glib-2.0/glib-object.h:23,from /usr/include/glib-2.0/gio/gioenums.h:28,from /usr/include/glib-2.0/gio/giotypes.h:28,from /usr/include/glib-2.0/gio/gio.h:26,from /home/path_to_project/src/main.c:3:
/usr/include/glib-2.0/glib/gtypes.h:32:10: Fatal error: glibconfig.h: No such file or directory
 #include <glibconfig.h>
          ^~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/vespa.dir/build.make:62: recipe for target 'CMakeFiles/vespa.dir/src/main.c.o' Failed
make[2]: *** [CMakeFiles/vespa.dir/src/main.c.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/vespa.dir/all' Failed
make[1]: *** [CMakeFiles/vespa.dir/all] Error 2
Makefile:151: recipe for target 'all' Failed
make: *** [all] Error 2

除非我错了,否则 cmake 错误似乎会阻止项目正确构建。所以我认为错误来自那里。事实上,当我尝试检查 glib2.0 lib 是否已正确安装时,我可以看到没有 /usr/lib/x86_64-linux-gnu/ 目录。我不明白为什么这个目录不是用模拟环境自动创建的。我试图通过手动安装 gcc 来创建它,但即便如此,它也没有安装依赖项。我什至尝试手动复制所有必需的依赖项,它部分工作,因为 cmake 命令成功,但 make 命令失败,说它缺少已安装的库。

这是我正在使用的 CMakeLists :

cmake_minimum_required(VERSION 3.10)

project(
    vespa 
    VERSION 0.2.0
    LANGUAGES C
)

find_package(PkgConfig)

pkg_check_modules(
    gst required IMPORTED_TARGET
    gstreamer-1.0
    gstreamer-rtsp-server-1.0
    gstreamer-rtsp-1.0
)

pkg_check_modules(
    glib required IMPORTED_TARGET
    glib-2.0
)

add_executable(
    vespa
    src/main.c
)

target_link_libraries(
    vespa
    PUBLIC
    m
    PkgConfig::gst
    PkgConfig::glib
)

install(
    TARGETS vespa
    DESTINATION bin
)

set_property(TARGET vespa PROPERTY VERSION ${vespa_VERSION})
set_property(TARGET vespa PROPERTY SOVERSION ${vespa_VERSION_MAJOR})

set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MInor ${PROJECT_VERSION_MInor})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libgstrtspserver-1.0-0 (>= 1.14.0-1)")
include(CPack)

我知道错误不是来自我使用的文件,也不是来自我使用的命令,因为它适用于所有尝试过的人。

我不明白是什么让它在我的电脑上失败了。

**************** 编辑 ****************

来自 Tarmo 的评论(谢谢)让我看向了另一个方向,我想我更好地理解了这个问题。

正如我所说,尝试运行时:

cmake ..

CMake 告诉我它试图找到“/usr/lib/x86_64-linux-gnu/glib-2.0/include”。哪个不存在,因为在这个模拟的 arm64 环境中,x86_64 路径不存在。

所以我尝试使用:

pkg-config --cflags glib-2.0

它返回了:

-I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include

在 arm64 环境中,这在我看来是合乎逻辑的。

所以看起来 pkg-config 在 cmd 行中正确定位了 glib,但在 CMakeLists.txt 中使用时则不然。我不明白为什么。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。