简体   繁体   English

pkg-config 找不到 gtk+-3.0

[英]pkg-config cannot find gtk+-3.0

I am trying to use libui-node to build a Node.js project.我正在尝试使用libui-node来构建一个 Node.js 项目。

$ 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.在 pkg-config 搜索路径中找不到 node-gyp configure build 包 gtk+-3.0。 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 |也许你应该把包含 `gtk+-3.0.pc' 的目录添加到 PKG_CONFIG_PATH 环境变量 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. sed s/-I//g' 在 binding.gyp 中返回退出状态 0。 while trying to load binding.gyp gyp ERR!在尝试加载 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.在 pkg-config 搜索路径中找不到包 gtk+-3.0。 Perhaps you should add the directory containing `gtk+-3.0.pc' to the PKG_CONFIG_PATH environment variable No package 'gtk+-3.0' found也许你应该将包含 `gtk+-3.0.pc' 的目录添加到 PKG_CONFIG_PATH 环境变量 No package 'gtk+-3.0' found

However, I have already installed gtk+-3.0 with this command:但是,我已经使用以下命令安装了 gtk+-3.0:

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

I am on Ubuntu 17.10.我在 Ubuntu 17.10 上。

My PKG_CONFIG_PATH :我的PKG_CONFIG_PATH

$ echo $PKG_CONFIG_PATH

/usr/lib/pkgconfig:/usr/local/lib/pkgconfig: /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 .使用pkg-config --variable pc_path pkg-config可以更轻松地显示pkg-config查找 .pc 文件的默认位置,如@BrettHale 在此 SO answer 中所述 This uses a special virtual pkg-config package to expose pkg-config configuration.这使用一个特殊的虚拟pkg-config包来公开pkg-config配置。 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.这比解析调试日志或使用strace (它不止一次挽救了我的一天)更容易,但重点是教我们如何在不知道去哪里查看时获取信息。

Original answer:原答案:

You shouldn't have to set PKG_CONFIG_PATH .您不必设置PKG_CONFIG_PATH Usually the paths your distro uses match the ones pkg-config will look into by default.通常,您的发行版使用的路径与默认情况下pkg-config将查看的路径相匹配。

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: 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

Those results are for my Ubuntu 14.04 system, but on Ubuntu 17.10 for amd64, the file has not moved, it's still:这些结果适用于我的 Ubuntu 14.04 系统,但在 Ubuntu 17.10 for amd64 上,文件没有移动,它仍然是:

/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 .现在该文件名为gtk+-3.0.pc ,因此pkg-config预期的模块名称是没有.pc扩展名的名称,即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.会告诉您它找不到gtk+3.0并且您应该更改PKG_CONFIG_PATH ,但实际上真正的问题是它是错误的模块名称,因为缺少-字符。

Now, we will run pkg-config in its default configuration, without customized PKG_CONFIG_PATH .现在,我们将在其默认配置中运行pkg-config ,没有自定义PKG_CONFIG_PATH This will check your system's default behavior, with pkg-config looking only in its default paths:这将检查您系统的默认行为, pkg-config仅查看其默认路径:

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

If this returns the version of GTK+, you're done.如果这返回了 GTK+ 的版本,那么您就完成了。 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.如果你仍然有错误消息说它没有找到,那么你可以检查pkg-config在调试日志中的默认位置。 Just add the --debug option:只需添加--debug选项:

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

This returns a quite verbose log of where it detects the .pc files.这将返回一个非常详细的日志,说明它检测到.pc文件的位置。 Here a the first few lines on may Ubuntu 14.04 system:这里是 Ubuntu 14.04 系统上的前几行:

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 .请注意以Cannot open directoryScanning directory开头的行。 They tell you where pkg-config is looking.它们会告诉您pkg-config在哪里查找。 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).这些在我的 14.04 和 Ubuntu 17.04 中是相同的(我在 docker 容器中检查过)。 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.你会注意到/usr/lib/x86_64-linux-gnu/pkgconfig是我的,所以找到了/usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-3.0.pc

If it's not there for you, then yes, you may add it to PKG_CONFIG_PATH :如果它不适合您,那么是的,您可以将其添加到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检测到的 GTK+ 库的版本:

pkg-config --modversion gtk+-3.0

It is due to .bbappend file removeing the x11 from the gtk+3 below path这是由于 .bbappend 文件从路径下面的 gtk+3 中删除了 x11

cat meta-freescale/recipes-graphics/gtk+/gtk+3_%.bbappend

PACKAGECONFIG_remove_imxgpu2d = " \
${@bb.utils.contains("DISTRO_FEATURES", "wayland", "x11", "", d)} \
"

CFLAGS_append_imxgpu2d = " \
-DLINUX \
${@bb.utils.contains('DISTRO_FEATURES', 'wayland', '-DEGL_API_FB
-DEGL_API_WL', '', d)} \

Instead of remove add append it will build successfully.它将成功构建而不是删除添加附加

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM