pkg-config 在 sysroot 目录下找不到包

发布于 2025-01-04 18:09:59 字数 662 浏览 3 评论 0原文

谁能告诉我为什么这可能会失败:

afeder@ubuntu:~/android/toolchain/sysroot$ ls $PKG_CONFIG_SYSROOT_DIR/usr/local/lib/pkgconfig/mozjs185.pc
/home/afeder/android/toolchain/sysroot/usr/local/lib/pkgconfig/mozjs185.pc

afeder@ubuntu:~/android/toolchain/sysroot$ pkg-config mozjs185 --cflags
Package mozjs185 was not found in the pkg-config search path.
Perhaps you should add the directory containing `mozjs185.pc'
to the PKG_CONFIG_PATH environment variable
No package 'mozjs185' found

根据 man pkg-config(1 )/usr/local/lib/pkgconfig 应该是默认搜索路径之一。

Can anyone please tell me why this might fail:

afeder@ubuntu:~/android/toolchain/sysroot$ ls $PKG_CONFIG_SYSROOT_DIR/usr/local/lib/pkgconfig/mozjs185.pc
/home/afeder/android/toolchain/sysroot/usr/local/lib/pkgconfig/mozjs185.pc

afeder@ubuntu:~/android/toolchain/sysroot$ pkg-config mozjs185 --cflags
Package mozjs185 was not found in the pkg-config search path.
Perhaps you should add the directory containing `mozjs185.pc'
to the PKG_CONFIG_PATH environment variable
No package 'mozjs185' found

According to man pkg-config(1), /usr/local/lib/pkgconfig is supposed to be one of the default search paths.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等往事风中吹 2025-01-11 18:09:59

我在这里找到了答案: http://www.flameeyes.eu/autotools -mythbuster/pkgconfig/cross-compiling.html

包装器脚本不应仅设置PKG_CONFIG_SYSROOT_DIR
变量:交叉编译时你想忽略包
安装在系统中,而只依赖那些安装在
交叉编译环境。这是通过重置来实现的
PKG_CONFIG_DIR(列出其他搜索路径),同时
时间设置PKG_CONFIG_LIBDIR以覆盖默认的基本搜索
路径。


生成的 CMake 文件将如下所示:

set(CMAKE_SYSROOT "/path/to/sysroot")

set(ENV{PKG_CONFIG_DIR} "")
set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig")
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})

免责声明:我使用了 CMAKE_SYSROOT 变量,当您想要将 -sysroot 传递给 g++ 时,该变量非常有用。如果您不希望这样,您应该以不同的方式命名您的变量。

I found the answer here: http://www.flameeyes.eu/autotools-mythbuster/pkgconfig/cross-compiling.html

The wrapper script should not only set the PKG_CONFIG_SYSROOT_DIR
variable: when cross-compiling you want to ignore the packages
installed in the system, and instead rely only on those installed in
the cross-compiled environment. This is achieved by resetting
PKG_CONFIG_DIR (which lists additional search paths), and at the same
time setting PKG_CONFIG_LIBDIR to override the default base search
paths.


The resulting CMake File would be something like this:

set(CMAKE_SYSROOT "/path/to/sysroot")

set(ENV{PKG_CONFIG_DIR} "")
set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig")
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})

Disclaimer: I used the CMAKE_SYSROOT variable which is useful when you want to pass -sysroot to g++. If you don't want this you should name your variable differently.

玩世 2025-01-11 18:09:59

如果您使用交叉编译器,则需要 1) 安装适当的 pkg-config 包装器,2) 设置包装器要选取的适当环境变量。您可以使用 apt-cache search pkg-config- 找到合适的包装器,然后为目标系统安装合适的包装器。例如,如果交叉编译到armhf:sudo apt-get install pkg-config-arm-linux-gnueabihf。然后,在调用包装器之前根据需要设置环境变量 PKG_CONFIG_DIRPKG_CONFIG_LIBDIRPKG_CONFIG_SYSROOT_DIR

如果您使用 CMake 进行交叉编译,请注意 CMake 的 pkg_search_module 命令(由 FindPkgConfig.cmake 提供)似乎无法正确设置包装器的环境。相反,您应该使用 PKG_CONFIG_PATH 环境变量。

# Set these in your toolchain.cmake file
set(triple arm-linux-gnueabihf)
set(PKG_CONFIG_EXECUTABLE ${triple}-pkg-config)
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/lib/${triple}/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig")

另请参阅在 cmake 中设置 PKG_CONFIG_PATH

If you're using a cross-compiler, then you need to 1) install the appropriate pkg-config wrapper and 2) set the appropriate environment variables to be picked up by the wrapper. You can find the appropriate wrapper with apt-cache search pkg-config- and then install the appropriate one for the target system. E.g. if cross-compiling to armhf: sudo apt-get install pkg-config-arm-linux-gnueabihf. Then, set environment variables PKG_CONFIG_DIR, PKG_CONFIG_LIBDIR, and PKG_CONFIG_SYSROOT_DIR as required before invoking the wrapper.

If you're cross compiling using CMake, note that CMake's pkg_search_module command (provided by FindPkgConfig.cmake) doesn't appear to correctly set the environment for the wrapper. Rather, you should use the PKG_CONFIG_PATH environment variable.

# Set these in your toolchain.cmake file
set(triple arm-linux-gnueabihf)
set(PKG_CONFIG_EXECUTABLE ${triple}-pkg-config)
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/lib/${triple}/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig")

See also set PKG_CONFIG_PATH in cmake

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文