1
votes

I resurrected some old code of mine which, rather frustratingly I now cannot compile. The undefined reference error at link-time suggests some weird static library issue but as I am linking against the standard gtkmm lib that doesn't make sense to me.

I am using GNU autotools and have started from scratch i.e.:

aclocal
automake --gnu --add-missing
autoconf
./configure
make

I've reduced the problem to a very simple test case:

#include <gtkmm/main.h>
#include <gtkmm/window.h>

int main(int argc, char *argv[])
{
    Gtk::Main kit(argc, argv);
    Gtk::Window window;
    Gtk::Main::run(window);

    return EXIT_SUCCESS;
}

and make invokes g++ at link-time as:

g++ `pkg-config gtkmm-2.4 --cflags` -ggdb -g -O2 `pkg-config gtkmm-2.4 --libs`  -o simple src/simple.o

which results in

src/simple.o: In function `main':
/home/ben/projects/qctviewer/src/simple.cpp:6: undefined reference to `Gtk::Main::Main(int&, char**&, bool)'

but I can link manually like this:

g++ -ggdb -g -O2 -o simple src/simple.o `pkg-config gtkmm-2.4 --cflags` `pkg-config gtkmm-2.4 --libs`

Maybe there is something screwy with my autotools setup, so for reference:

Makefile.am

AUTOMAKE_OPTIONS = subdir-objects
AM_CXXFLAGS = `pkg-config gtkmm-2.4 --cflags` -ggdb
AM_LDFLAGS = `pkg-config gtkmm-2.4 --libs`   
bin_PROGRAMS = simple   
simple_SOURCES = src/simple.cpp

configure.ac

AC_PREREQ([2.68])
AC_INIT([qctviewer], [0.4.0], [[email protected]], [qctviewer], [http://bangham.com/qctviewer])
AC_CONFIG_SRCDIR([src/palette.cpp])
AC_CONFIG_HEADERS([config.h])
AC_PROG_CXX
AC_PROG_CC
AC_HEADER_STDBOOL
AM_INIT_AUTOMAKE([1.9 foreign])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

in case it's relevant, the relevant libraries installed are:

ben@linux:~$ dpkg --get-selections | grep gtkmm
libgtkmm-2.4-1c2a               install
libgtkmm-2.4-dev                install
libgtkmm-3.0-1              install
libgtkmm-3.0-dev                install

and I have run this against the 3.0 libraries with the same result.

TIA, Ben.

1

1 Answers

4
votes

Doh, I finally found the magic search terms which pointed me to the answer.

Linker flags in wrong place shows that I am mis-using LDFLAGS and should instead use LDADD.

Added to configure.ac:

PKG_CHECK_MODULES([libgtkmm], [gtkmm-3.0])

Amended in Makefile.am:

AM_CXXFLAGS = ${libgtkmm_CFLAGS}
# AM_LDFLAGS ....
simple_LDADD = ${libgtkmm_LIBS}