My project depends upon a library (more precisely, GTK+) so I added the following configurations in my configure.ac:
PKG_CHECK_MODULES([GTK], [gtk+-2.0])
AC_SUBST([GTK_CFLAGS])
AC_SUBST([GTK_LIBS])
My Makefile.am is:
bin_PROGRAMS = secretary
secretary_SOURCES = secretary.c
For its turn, my secretary.c is as follows:
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show(window);
gtk_main();
return 0;
}
However, when I run make (of course, after calling ./configure) I got this error:
gcc -DHAVE_CONFIG_H -I. -g -O2 -MT secretary.o -MD -MP -MF \
.deps/secretary.Tpo -c -o secretary.o secretary.c
secretary.c:1:21: fatal error: gtk/gtk.h: File or directory not found.
What am I missing? Why does autoconf not pass the correct flags to gcc?
When you use
PKG_CHECK_MODULES, you need to specify the flags inMakefile.am. The easiest way is to add it toAM_LDFLAGSandAM_CPPFLAGS:If you want to be more specific, you can instead add:
It is probably easier to not use
PKG_CHECK_MODULESat all and let the user specify the location of the libraries through the usual mechanism (assigningLDFLAGSor installing the libraries in a standard location).