且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CMake交叉编译无法找到库

更新时间:2022-05-25 18:47:49

感谢@Tsyvarev,问题出在pkg-config.在主机上,我有:

Thanks to @Tsyvarev, The problem was pkg-config. in host i have:

myPC:~$ pkg-config --libs gstreamer-1.0
Package gstreamer-1.0 was not found in the pkg-config search path.

但在目标BeagleBone中:

but in target BeagleBone :

beaglebone:~# pkg-config --modversion  gstreamer-1.0
1.4.4

和目标中.pc文件的路径为:

and the path for .pc files in target are :

   beaglebone:~# pkg-config --variable pc_path pkg-config
    /usr/local/lib/arm-linux-gnueabihf/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig

[错误的方式!] 所以我只是将这些带有/mnt/BBB前缀(我的目标rootfs)的路径添加到主机的pkg-config环境中并运行cmake,一切都得到了公认:

[Wrong Way !] so i simply added these path with prefix of /mnt/BBB (my target rootfs) to pkg-config environment of host and run cmake, everything well recognized :

myPC:~$ export PKG_CONFIG_PATH=/mnt/BBB/usr/local/lib/arm-linux-gnueabihf/pkgconfig:/mnt/BBB/usr/local/lib/pkgconfig:/mnt/BBB/usr/local/share/pkgconfig:/mnt/BBB/usr/lib/arm-linux-gnueabihf/pkgconfig:/mnt/BBB/usr/lib/pkgconfig:/mnt/BBB/usr/share/pkgconfig
myPC:~$ cmake-gui

根据此链接,我需要创建 pkg-config包装器脚本. 在我的工具链目录中,我有 arm-linux-gnueabihf-pkg-config-real ,然后我应该将其脚本修改为此:

According to This link, i need to create pkg-config wrapper script. in my toolchain Directory i have arm-linux-gnueabihf-pkg-config-real and then i should modify its script to this:

#!/bin/sh
#
# Wrapper script that calls the real pkg-config with the relocated
# sysroot location
#
set -e

GCC="${0%%-pkg-config}-gcc" 
MACHINE=`"$GCC" -dumpmachine`
SYSROOT=`"$GCC" -print-sysroot`
SYSROOT=/mnt/BBB              #My modification
export PKG_CONFIG_DIR=
export PKG_CONFIG_LIBDIR="${SYSROOT}/usr/lib/${MACHINE}/pkgconfig":"${SYSROOT}/usr/lib/pkgconfig":"${SYSROOT}/usr/share/pkgconfig"
export PKG_CONFIG_SYSROOT_DIR="${SYSROOT}"

exec "$0-real" "$@"

然后在 toolchain.cmake

set(PKG_CONFIG_EXECUTABLE /usr/gcc-linaro-arm-linux-gnueabihf-4.7/bin/arm-linux-gnueabihf-pkg-config)

一切都很好...