Portable include GLib headers in autoconf / automake

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

How can I safely import GLib headers in a portable way? I know about pkg-config , but this is not entirely portable (since some systems do not have one, and I would rather rely only on autoconf for configuration).

+6
autotools autoconf automake pkg-config
source share
2 answers

The GLib 2.22 INSTALL file indicates that pkg-config is required to install this library. I am not GLib (pun!); asserting this requirement is one of the first things at the top of the INSTALL file.

It is not clear from the text surrounding it whether pkg-config required to compile GLib, but it is clear that the authors of GLib 2.22 do not intend to compile users with GLib without pkg-config. In particular, GLib make install will install .pc files .pc .

For platform portability, let the user set $PKG_CONFIG_PATH accordingly.

+4
source share

Using the PKG_CHECK_MODULES macro, configure scripts created by Autoconf can automatically extract pkg-config data. For example, adding this line to your configure.ac file:

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

will produce the configure script result to verify that the installed version of glib-2.0 is greater than or equal to version 2.24.1, and also add the output pkg-config --cflags glib-2.0 and pkg-config --libs glib-2.0 to the variables DEPS_CFLAGS and pkg-config --libs glib-2.0 respectively. Then you use the variables $(DEPS_CFLAGS) and $(DEPS_LIBS) in the primary elements _CFLAGS and _LDADD :

 bin_PROGRAMS = hello hello_CFLAGS = $(DEPS_CFLAGS) hello_SOURCES = hello.c hello_LDADD = $(DEPS_LIBS) 
+12
source share

All Articles