Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portably include GLib headers in autoconf/automake

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).

like image 241
alternative Avatar asked Nov 14 '09 00:11

alternative


2 Answers

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

bin_PROGRAMS = hello

hello_CFLAGS = $(DEPS_CFLAGS)
hello_SOURCES = hello.c
hello_LDADD = $(DEPS_LIBS)
like image 178
Daniel Trebbien Avatar answered Sep 22 '22 03:09

Daniel Trebbien


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.

like image 37
Setjmp Avatar answered Sep 20 '22 03:09

Setjmp