1
votes

I'm attempting to setup an autotools build system for one of my Vala projects, here is what I've come up with so far.

configure.ac

AC_INIT(White House, 1.0)
AC_CONFIG_SRCDIR(src/Window.vala)

AM_INIT_AUTOMAKE

AC_PROG_CC
AC_PROG_CC_STDC
AM_PROG_VALAC([0.7.0])
AC_PROG_INSTALL

WHITE_HOUSE_PACKAGES="--pkg gio-2.0 --pkg gtk+-3.0 --pkg gee-0.8 --target-glib 2.32 --pkg json-glib-1.0"
PKG_CHECK_MODULES(WHITE_HOUSE, [gio-2.0 gtk+-3.0 gee-0.8 json-glib-1.0])
AC_SUBST(WHITE_HOUSE_CFLAGS)
AC_SUBST(WHITE_HOUSE_LIBS)
AC_SUBST(WHITE_HOUSE_PACKAGES)

AC_CONFIG_FILES([
   Makefile
   resources/white-house.desktop
   resources/Makefile
   src/Makefile
])
AC_OUTPUT

Makefile.am

SUBDIRS = resources src
EXTRA_DIST = autogen.sh

src/Makefile.am

AM_CPPFLAGS = $(WHITE_HOUSE_CFLAGS)
bin_PROGRAMS = white-house

white_house_SOURCES = AutomapDialog.vala Drawable.vala Map.vala Preferences.vala Room.vala TextView.vala AutoMapper.vala Handle.vala Passage.vala RoomDialog.vala Tab.vala Window.vala
white_house_VALAFLAGS = $(WHITE_HOUSE_PACKAGES)

white_house_CFLAGS = $(WHITE_HOUSE_CFLAGS)

white_house_LDFLAGS = $(WHITE_HOUSE_LIBS)

resources/Makefile.am

desktopdir = $(datadir)/applications
desktop_DATA = white-house.desktop

icondir = $(datadir)/icons
icon_DATA = white-house.svg

When I run make I get a lot of errors in the form of src/File.c:####: undefined reference to some_function (). This looks to me like it's not passing the CFLAGS correctly. What did I do wrong?

Edit: After further research I discovered that 'undefined reference' errors can occur if the sources files are passed to gcc after the libs. Here is the command make is using.

gcc -std=gnu99 -pthread -I/usr/local/include/gee-0.8 -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/mirclient -I/usr/include/mircommon -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/json-glib-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include  -g -O2 -L/usr/local/lib -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgee-0.8 -ljson-glib-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0   -o white-house white_house-Window.o

As you can see the source files are the last thing on the line. If I move them before the -l arguments it compiles fine. So the question is: Why is the Makefile putting them in the wrong order?

2

2 Answers

2
votes

Looks like I should be using LDADD instead of LDFLAGS. My new Makefile.am is as follows.

bin_PROGRAMS = white-house

white_house_SOURCES = AutomapDialog.vala Drawable.vala Map.vala Preferences.vala Room.vala TextView.vala AutoMapper.vala Handle.vala Passage.vala RoomDialog.vala Tab.vala Window.vala
white_house_VALAFLAGS = $(WHITE_HOUSE_PACKAGES) --target-glib 2.32
white_house_CFLAGS = $(WHITE_HOUSE_CFLAGS)
white_house_LDADD = $(WHITE_HOUSE_LIBS) -lm
1
votes

You generally want to set white_house_CPPFLAGS, not white_house_CFLAGS. The CPPFLAGS get passed to both the compiler and some pre-processing steps. Also, you should be able to see the commands before they are executed. If not, try make V=1.