pkg-config 找不到 gtk+-3.0 [英] pkg-config cannot find gtk+-3.0

查看:79
本文介绍了pkg-config 找不到 gtk+-3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 libui-node 来构建 Node.js 项目.

$ yarn add libui-node

这给出了一个错误:

<块引用>

node-gyp configure build Package gtk+-3.0 在pkg-config 搜索路径.也许你应该添加目录包含 `gtk+-3.0.pc' 到 PKG_CONFIG_PATH 环境变量找不到包 'gtk+-3.0' gyp:调用 'pkg-config gtk+-3.0--cflags-only-I |sed s/-I//g' 在 binding.gyp 中返回退出状态 0.在尝试加载 binding.gyp gyp ERR 时!配置错误...

然后我按照说明进行操作:

$ pkg-config gtk+-3.0 --cflags-only-I |sed s/-I//g

<块引用>

包 gtk+-3.0 是在 pkg-config 搜索路径中找不到.也许你应该添加包含 `gtk+-3.0.pc' 的目录到 PKG_CONFIG_PATH 环境变量没有找到包'gtk+-3.0'

不过,我已经用这个命令安装了 gtk+-3.0:

$ sudo apt-get install build-essential libgtk-3-dev

我在 Ubuntu 17.10 上.

我的PKG_CONFIG_PATH:

$ echo $PKG_CONFIG_PATH

<块引用>

/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:

我应该如何配置我的系统以便它可以找到这个库?

解决方案

<块引用>

如@BrettHale 所述,使用 pkg-config --variable pc_path pkg-config 可以更轻松地显示 pkg-config 查找 .pc 文件的默认位置在这个答案中.这使用一个特殊的虚拟 pkg-config 包来公开 pkg-config 配置.这比解析调试日志或使用 strace (它不止一次地节省了我的一天)更容易,但重点更多的是教我们如何在不知道去哪里查找信息时获取信息.

原答案:

您不必设置 PKG_CONFIG_PATH.通常,您的发行版使用的路径与 pkg-config 默认情况下会查找的路径相匹配.

pkg-config 查找与 GTK+ 3 关联的 .pc.当您安装了 libgtk-3-dev 开发包时,您可以在其中找到它提供的 .pc 文件:

$ dpkg -L libgtk-3-dev |grep '.pc'/usr/lib/x86_64-linux-gnu/pkgconfig/gdk-wayland-3.0.pc/usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-unix-print-3.0.pc/usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-3.0.pc/usr/lib/x86_64-linux-gnu/pkgconfig/gdk-3.0.pc/usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-wayland-3.0.pc/usr/lib/x86_64-linux-gnu/pkgconfig/gdk-x11-3.0.pc/usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-x11-3.0.pc

这些结果适用于我的 Ubuntu 14.04 系统,但在 Ubuntu 17.10 for amd64 上,文件没有移动,它仍然是:

/usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-3.0.pc

现在文件名为 gtk+-3.0.pc,因此 pkg-config 所期望的模块名称是没有 .pc 的名称 扩展名,即 gtk+-3.0.这有助于确保您没有在模块名称中打错字.

例如,

pkg-config --modversion gtk+3.0

会告诉你它找不到 gtk+3.0 并且你应该更改 PKG_CONFIG_PATH,但实际上真正的问题是它的模块名称是错误的缺少 - 字符.

现在,我们将以默认配置运行 pkg-config,无需自定义 PKG_CONFIG_PATH.这将检查您系统的默认行为,pkg-config 仅查看其默认路径:

取消设置 PKG_CONFIG_PATHpkg-config --modversion gtk+-3.0

如果这会返回 GTK+ 的版本,那么您就完成了.如果您仍然有错误消息说它没有找到,那么您可以检查默认情况下 pkg-config 在调试日志中的位置.只需添加 --debug 选项:

pkg-config --debug --modversion gtk+-3.0

这会返回一个非常详细的日志,说明它检测到 .pc 文件的位置.这是 Ubuntu 14.04 系统的前几行:

选项 --debug seen选项 --modversion 看到由于使用--version、--libs、--cflags、--libs-only-l、--libs-only-L、--libs-only-other、--cflags-only,默认启用错误打印-I、--cflags-only-other 或--list.--silence-errors 的值:0启用错误打印将虚拟pkg-config"包添加到已知包列表无法在包搜索路径中打开目录/usr/local/lib/x86_64-linux-gnu/pkgconfig":没有这样的文件或目录无法在包搜索路径中打开目录/usr/local/lib/pkgconfig":没有这样的文件或目录无法在包搜索路径中打开目录/usr/local/share/pkgconfig":没有这样的文件或目录扫描目录'/usr/lib/x86_64-linux-gnu/pkgconfig'[...]

注意以 Cannot open directoryScanning directory 开头的行.他们告诉你 pkg-config 在哪里寻找.让我们只显示:

$ pkg-config --debug --modversion gtk+-3.0 2>&1 |egrep "(无法打开|扫描) 目录"无法在包搜索路径中打开目录/usr/local/lib/x86_64-linux-gnu/pkgconfig":没有这样的文件或目录无法在包搜索路径中打开目录/usr/local/lib/pkgconfig":没有这样的文件或目录无法在包搜索路径中打开目录/usr/local/share/pkgconfig":没有这样的文件或目录扫描目录'/usr/lib/x86_64-linux-gnu/pkgconfig'扫描目录'/usr/lib/pkgconfig'扫描目录'/usr/share/pkgconfig'

现在您拥有了所有要搜索的位置.这些在我的 14.04 和 Ubuntu 17.04 中是相同的(我在 docker 容器中检查过).其中一些目录存在,其他目录不存在.你会注意到 /usr/lib/x86_64-linux-gnu/pkgconfig 是我的,所以 /usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-3.0.pc 找到了.

如果它不适合你,那么是的,你可以将它添加到 PKG_CONFIG_PATH:

导出 PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig

现在应该返回 pkg-config 检测到的 GTK+ 库的版本:

pkg-config --modversion gtk+-3.0

I am trying to use libui-node to build a Node.js project.

$ yarn add libui-node

This gives an error:

node-gyp configure build Package gtk+-3.0 was not found in the pkg-config search path. Perhaps you should add the directory containing `gtk+-3.0.pc' to the PKG_CONFIG_PATH environment variable No package 'gtk+-3.0' found gyp: Call to 'pkg-config gtk+-3.0 --cflags-only-I | sed s/-I//g' returned exit status 0 while in binding.gyp. while trying to load binding.gyp gyp ERR! configure error ...

So then I follow the instructions:

$ pkg-config gtk+-3.0 --cflags-only-I | sed s/-I//g 

Package gtk+-3.0 was not found in the pkg-config search path. Perhaps you should add the directory containing `gtk+-3.0.pc' to the PKG_CONFIG_PATH environment variable No package 'gtk+-3.0' found

However, I have already installed gtk+-3.0 with this command:

$  sudo apt-get install build-essential libgtk-3-dev

I am on Ubuntu 17.10.

My PKG_CONFIG_PATH:

$ echo $PKG_CONFIG_PATH

/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:

How should I configure my system so that it can find this library?

解决方案

EDIT:

Showing the default locations where pkg-config looks for .pc files is more easily done with pkg-config --variable pc_path pkg-config as stated by @BrettHale in this SO answer. This uses a special virtual pkg-config package to expose pkg-config configuration. This is easier than parsing the debug logs or using strace (which saved my day more than once), but the point was more on teaching how to get information when we don't know where to look.

Original answer:

You shouldn't have to set PKG_CONFIG_PATH. Usually the paths your distro uses match the ones pkg-config will look into by default.

pkg-config looks for the .pc associated with GTK+ 3. As you have installed the libgtk-3-dev development package, you find in it the .pc files it provides using:

$ dpkg -L libgtk-3-dev | grep '.pc'
/usr/lib/x86_64-linux-gnu/pkgconfig/gdk-wayland-3.0.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-unix-print-3.0.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-3.0.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/gdk-3.0.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-wayland-3.0.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/gdk-x11-3.0.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-x11-3.0.pc

Those results are for my Ubuntu 14.04 system, but on Ubuntu 17.10 for amd64, the file has not moved, it's still:

/usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-3.0.pc

Now the file is named gtk+-3.0.pc, so the name of the module as expected by pkg-config is that name without the .pc extension, which is gtk+-3.0. This helps making sure you didn't make a typo in the module name.

For example,

pkg-config --modversion gtk+3.0

would tell you it can't find gtk+3.0 and that you should change PKG_CONFIG_PATH, but in fact the real problem is that it's the wrong module name as there's a missing - character.

Now, we will run pkg-config in its default configuration, without customized PKG_CONFIG_PATH. This will check your system's default behavior, with pkg-config looking only in its default paths:

unset PKG_CONFIG_PATH
pkg-config --modversion gtk+-3.0

If this returns the version of GTK+, you're done. If you still have the error message saying it's not found though, then you may check where pkg-config looks by default in the debug logs. Just add the --debug option:

pkg-config --debug --modversion gtk+-3.0

This returns a quite verbose log of where it detects the .pc files. Here a the first few lines on may Ubuntu 14.04 system:

Option --debug seen
Option --modversion seen
Error printing enabled by default due to use of --version, --libs, --cflags, --libs-only-l, --libs-only-L, --libs-only-other, --cflags-only-I, --cflags-only-other or --list. Value of --silence-errors: 0
Error printing enabled
Adding virtual 'pkg-config' package to list of known packages
Cannot open directory '/usr/local/lib/x86_64-linux-gnu/pkgconfig' in package search path: No such file or directory
Cannot open directory '/usr/local/lib/pkgconfig' in package search path: No such file or directory
Cannot open directory '/usr/local/share/pkgconfig' in package search path: No such file or directory
Scanning directory '/usr/lib/x86_64-linux-gnu/pkgconfig'
[...]

Notice the lines starting with Cannot open directory and Scanning directory. They tell you where pkg-config is looking. Let's only display that:

$ pkg-config --debug --modversion gtk+-3.0 2>&1 | egrep "(Cannot open|Scanning) directory"
Cannot open directory '/usr/local/lib/x86_64-linux-gnu/pkgconfig' in package search path: No such file or directory
Cannot open directory '/usr/local/lib/pkgconfig' in package search path: No such file or directory
Cannot open directory '/usr/local/share/pkgconfig' in package search path: No such file or directory
Scanning directory '/usr/lib/x86_64-linux-gnu/pkgconfig'
Scanning directory '/usr/lib/pkgconfig'
Scanning directory '/usr/share/pkgconfig'

Now you have all the locations that are searched for. Those are the same in my 14.04 and in Ubuntu 17.04 (I checked that in a docker container). Some of those directories exist, others don't. You will notice that /usr/lib/x86_64-linux-gnu/pkgconfig is there for me, so /usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-3.0.pc is found.

If it's not there for you, then yes, you may add it to PKG_CONFIG_PATH:

export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig

This should now return the version of the GTK+ library detected by pkg-config:

pkg-config --modversion gtk+-3.0

这篇关于pkg-config 找不到 gtk+-3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆