views:

331

answers:

2

I need to include the GLib headers for a project that is built with an autoconf-based system for portability.

How can I safely import the GLib headers in a portable manner? I know about pkg-config, but that is not entirely portable (since some systems don't have it and I would prefer to only rely on autoconf for configuration).

+1  A: 

The GLib 2.22 INSTALL file states that pkg-config is a requirement for installing this library. I am not being GLib (pun intended!); statement of this requirement is one of the first things on the top of the INSTALL file.

From the text surrounding it is unclear whether pkg-config is needed to compile GLib itself, however it is clear that GLib 2.22 authors do not intend for any users to compile against GLib without having pkg-config. In particular, GLib's make install will install .pc files appropriately.

For platform portability, instruct the user to set $PKG_CONFIG_PATH appropriately.

SetJmp
+1  A: 

By using the PKG_CHECK_MODULES macro, Autoconf-generated configure scripts can retrieve pkg-config data automatically. As an example, adding this line to your configure.ac file:

PKG_CHECK_MODULES([DEPS], [glib-2.0 >= 2.24.1])

will cause the resulting configure script to ensure that the installed version of glib-2.0 is greater than or equal to version 2.24.1 as well as append to variables DEPS_CFLAGS and DEPS_LIBS the output of pkg-config --cflags glib-2.0 and pkg-config --libs glib-2.0, respectively. You then use the $(DEPS_CFLAGS) and $(DEPS_LIBS) variables in the _CFLAGS and _LIBS primaries:

bin_PROGRAMS = hello

hello_CFLAGS = $(DEPS_CFLAGS)
hello_SOURCES = hello.c
hello_LIBS = $(DEPS_LIBS)
Daniel Trebbien