how to map pkg-config names to yum/apt-get

2019-06-20 07:15发布

问题:

Lots of makefiles use pkg-config but the names don't relate to package managers (e.g. yum / apt). How to map pkg-config names to them? is there a trick?

Example: if I do yum searchName -- look through the name and approximate to pkg-config's name

Result:

$ pkg-config --libs dbus-glib-0
Package dbus-glib-0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `dbus-glib-0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'dbus-glib-0' found

$ sudo yum install dbus-glib
Loaded plugins: langpacks, refresh-packagekit
Package dbus-glib-0.100-5.fc19.i686 already installed and latest version
Nothing to do

$ sudo yum install dbus-glib-0
Loaded plugins: langpacks, refresh-packagekit
No package dbus-glib-0 available.
Error: Nothing to do

回答1:

In the case of apt-get, if you have some software that complains about this missing package via pkg-config, for instance:

configure: error: Package requirements (gtk+-2.0 >= 2.8) were not met:

No package 'gtk+-2.0' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables GTK_CFLAGS
and GTK_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
Error: Could not run ./configure, which is required to configure banshee

Then it means that the configure script is looking for the gtk+-2.0 pkgconfig package.

Then, what you can do is this:

$ sudo apt-get install apt-file
...
$ apt-file update
...
$ apt-file search gtk+-2.0 | grep "\.pc"
libgtk2.0-dev: /usr/lib/x86_64-linux-gnu/pkgconfig/gtk+-2.0.pc

Which means you can install package libgtk2.0-dev:

sudo apt-get install libgtk2.0-dev

And the dependency would be satisfied.

In the particular case of the original question:

$ apt-file search --package-only dbus-glib-1.pc
libdbus-glib-1-dev

(dbus-glib-0 seems to be too old to show up in my system.)



回答2:

The pkg-config files are usually provided by the -devel package so in most cases foo.pc is provided by libfoo-devel. That's still guesswork, but there are two shortcuts:

Installing by path name, if you know where the .pc file will end up

 $> yum install /usr/lib64/pkgconfig/foo.pc

That works for any file, but you still need to guess where the .pc file is. The best approach is using the actual pkgconfig requirement:

$> yum install "pkgconfig(foo)"

Use the quotes to avoid the shell trying to interpret the parenthesis.