Tuesday, June 5, 2012

pkg-config and empty CFLAGS

I ran into this a few days ago and it took me a while to find. One of the gnome modules failed to build with an error of "cannot find <gtk/gtk.h>". At first I thought it was a Makefile.am/configure.ac error but it appears the issue sits deeper. Cause of the problem was a stale gtk installation, but finding that was tricky. The configure.ac file contains essentially
PKG_CHECK_MODULES(GTK, gtk+-2.0)
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
Turns out that PKG_CHECK_MODULES in configure.ac gets translated to
pkg-config --exists --print-errors gtk+-2.0
This returns 0 (success) on my machine - the gtk+-2.0.pc file is there. However, to get the CFLAGS, configure runs a different command and that returned an error:
$> pkg-config --cflags gtk+-2.0
Package libpng12 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libpng12.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libpng12', required by 'GdkPixbuf', not found
Alas, this error isn't shown anywhere and it doesn't end up in the log either. What does happen though is that GTK_CFLAGS gets replaced with an empty string, causing the build error above. Once I installed the required libpng everything works fine. But if you ever run into issues where the CFLAGS aren't quite what they should be, check the pkg-config commands for success.

[Update Jun 07 2012]
As pointed out in the comments, looks like we're looking at https://bugs.freedesktop.org/show_bug.cgi?id=4738 and https://bugs.freedesktop.org/show_bug.cgi?id=43149 here.

3 comments:

Charles said...

Sounds like it would be more useful if PKG_CHECK_MODULES used --cflags then to actually ensure that dependencies are available (and hopefully also report the underlying error as a result).

Dan Nicholson said...

https://bugs.freedesktop.org/show_bug.cgi?id=43149

https://bugs.freedesktop.org/show_bug.cgi?id=4738

Definitely some bugs there, but I haven't dove into that one in a while.

Dan Nicholson said...

https://bugs.freedesktop.org/show_bug.cgi?id=4738

https://bugs.freedesktop.org/show_bug.cgi?id=4738

Definitely some bugs, but also some tangled history. I haven't dove back into that one yet.