Tomasz Gebarowski

Problem with PKG_CHECK_MODULES under Mac OS X

Yesterday I had some problem with compiling my Glib application under Mac OS X. I knew that everything worked before on Debian and the problem had to be one of this darwin-specific.

Just to make myself clear. Here is the error I got after executing: ./configure

 checking for pkg-config... pkg-config<br />
./configure: line 3489: syntax error near unexpected token `GLIB,'<br />
./configure: line 3489: `PKG_CHECK_MODULES(GLIB, glib-2.0)'<br />

It seemed that there was some problem with PKG_CHECK_MODULES – autoconf’s macro responsible for detecting if a given library or module was installed in the system (basing on pkg-config).

In fact it came out that the macro was not defined at all. Normally after running aclocal command it should be generated in the file aclocal.m4. But in my situation there was no such entry.

Why did that occur? At that time I could not answer that question but at least I had some starting point.

You may probably know that aclocal is one of the tools of Autotools package. It creates a file named aclocal.m4 which includes a number of Autoconf macros that can be used later by configure. (one of these macros is of course PKG_CHECK_MODULES)

After reading the aclocal info page I found out that the aclocal.m4 file content was based on some external .m4 files and my configure.ac. I read that the PKG_CHECK_MODULES macro should be defined inside pkg.m4 file, and I really could find it there in my directory /opt/local/share/aclocal .

And here the answer came. I installed pkg-config and Glib using darwin ports, where the default prefix for packages was /opt/local. But on the other hand all the Autotools programs were located in /usr/bin. It was obvious that the prefix was different, so that aclocal could not detect pkg.m4 file and define PKG_CHECK_MODULES macro.

The only missing thing was to inform aclocal about the path of pkg.m4 and all other external .m4 files.

It was simple and could be done by adding extra parameter -I:

aclocal -I /opt/local/share/aclocal<br />

Now after running my autogen.sh file which more or less looked liked that:

aclocal -I /opt/local/share/aclocal<br />
autoheader<br />
automake<br />
autoconf<br />

and later

./configure<br />
make<br />

my application was compiled.

Of course this can be also achieved in many different ways. To find more solutions I recommend studying _aclocal_info page (especially secion Macro Search Path)