1
votes

My first autotools project, might be something simple and dumb: it's creating a makefile that can't find glib and other 3rd party libraries. (Running Ubuntu Linux, compiling a C static library if that matters.)

Configure.ac includes these lines:

PKG_CHECK_MODULES([libglib], [glib-2.0 >= 2.28])
PKG_CHECK_MODULES([libobject], [gobject-2.0 >= 2.28])
PKG_CHECK_MODULES([libuuid], [uuid])

Makefile.am is as follows

lib_LIBRARIES=libblah.a
libblah_a_SOURCES=blah.c util.c
libblah_a_CPPFLAGS=$(libglib_CFLAGS) $(libobject_CFLAGS) $(libuuid_CFLAGS)
libblah_a_LIBADD=$(libglib_LIBS) $(libobject_LIBS) $(libuuid_LIBS)

Running autoreconf --install generates Makefile.in with this:

libglib_CFLAGS = @libglib_CFLAGS@
libglib_LIBS = @libglib_LIBS@
libobject_CFLAGS = @libobject_CFLAGS@
libobject_LIBS = @libobject_LIBS@
libuuid_CFLAGS = @libuuid_CFLAGS@
libuuid_LIBS = @libuuid_LIBS@

Looks good! Except then the configure script claims it found these libraries yet spits out a Makefile that converts the above line into this uselessness:

libglib_CFLAGS = 
libglib_LIBS = 
libobject_CFLAGS = 
libobject_LIBS = 
libuuid_CFLAGS = 
libuuid_LIBS = 

Help!

Edit: Here is the full configure.ac file:

AC_INIT([amblah], [1.0], [[email protected]])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
 Makefile
 libblah/Makefile
 tests/Makefile
])
AC_OUTPUT
AC_PROG_RANLIB
PKG_PROG_PKG_CONFIG(0.26)
PKG_CHECK_MODULES([libglib], [glib-2.0 >= 2.28])
PKG_CHECK_MODULES([libobject], [gobject-2.0 >= 2.28])
PKG_CHECK_MODULES([libuuid], [uuid])
1
What output do you get when you run pkg-config directly?William Pursell
Perhaps you are running the configure script with in sane mode with PKG_CONFIG=true. (Note that this is somewhat tongue-in-cheek: PKG_CONFIG=true effectively disables PKG_CHECK_MODULES and requires the user to assign LDFLAGS and CPPFLAGS correctly.)William Pursell
Is this just missing AC_SUBST(XXX_CFLAGS) and AC_SUBST(XXX_LIBS) for those libraries?Etan Reisner
@WilliamPursell: pkg-config detects the libraries. I was using it with my handcrafted Makefile before attempting the migration to autotools. Example, pkg-config --libs glib-2.0 gives -lglib-2.0. As for PKG_CONFIG, I'm not explicitly setting it anywhere. A grep of the files shows this in config.log: PKG_CONFIG='/usr/bin/pkg-config'.David M
@EtanReisner: I'm not familiar with AC_SUBST. I'll add the full configure.ac file above.David M

1 Answers

1
votes

Doh! I see the problem, and it is definitely a dumb newb problem. AC_OUTPUT is what makes it spit out Makefile output and so forth. The GNU tutorial wasn't clear on this fact, and I had put some lines below AC_OUTPUT. Thus those lines were not considered when AC_OUTPUT generated its output. By moving AC_OUTPUT to the very end, it fixes the problem.