babb517
babb517

Reputation: 15

Automake not including object files in built static library

I currently have a largish project including multiple applications and am trying to build a static library along with one of my applications for inclusion in several of the other applications.

I followed the tutorial provided at http://www.gnu.org/software/automake/manual/html_node/A-Library.html and have set up the appropriate Makefile.am as follows:

include Makefile.shared

noinst_LIBRARIES = libas2transition.a
bin_PROGRAMS = as2transition

BUILT_SOURCES = \
    TransitionFormatter.cpp

libas2transition_a_SOURCES =
    TransitionFormatter.re2c \
    TransitionPath.cpp \
    Timestep.cpp \
    Predicate.cpp \
    StringUtils.cpp

as2transition_SOURCES = \
    main.cpp

as2transition_LDADD = libas2transition.a

Makefile.shared contains shared configuration for all my subprojects and contains:

if DEBUG
AM_CFLAGS = -g3 -O0 -DDEBUG
AM_CXXFLAGS = -g3 -O0 -DDEBUG --std=c++0x
else
AM_CFLAGS = -O3 -DNDEBUG
AM_CXXFLAGS = -O3 -DNDEBUG --std=c++0x
endif

if MAINTAINER_MODE
if HAVE_RE2C
.re2c.cpp:
    $(RE2C) -o $@ $^
else
.re2c.cpp:
    @- echo "ERROR: Configured to build in maintainer mode but re2c is not installed on the computer."
    @- echo "ERROR: Modified re2c files cannot be compiled into the corresponding .cpp file."
    @- echo "ERROR: Please install re2c before continuing."
    @- exit 1
endif
else
.re2c.cpp:
    @- echo "WARNING: The system must be configured to build in maintainer mode in order to rebuild re2c files."
    @- echo "WARNING: These files will not be rebuilt unless you rerun the configure script with the '--enable-maintainer-mode' flag."
endif

As far as I can tell everything is set up properly to first build the static library libas2transition.a and then compile a binary linking against it. However, when I attempt to run make I get the following output (note that this was a fresh build after a make clean).

make  all-am
make[1]: Entering directory `/home/jbabb1/workspace/as2transition/src'
rm -f libas2transition.a
ar cru libas2transition.a
ranlib libas2transition.a
g++ -DHAVE_CONFIG_H -I. -I..    -O3 -DNDEBUG --std=c++0x -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.cpp
mv -f .deps/main.Tpo .deps/main.Po
g++ -O3 -DNDEBUG --std=c++0x -g -O2   -o as2transition main.o libas2transition.a
main.o: In function `as2transition::TransitionFormatter::format(std::basic_istream<char, std::char_traits<char> >&, std::basic_ostream<char, std::char_traits<char> >&, bool) const':
/home/jbabb1/workspace/as2transition/src/TransitionFormatter.h:123: undefined reference to `as2transition::TransitionFormatter::format(std::basic_istream<char, std::char_traits<char> >&, bool) const'
/home/jbabb1/workspace/as2transition/src/TransitionFormatter.h:124: undefined reference to `as2transition::TransitionPath::output(std::basic_ostream<char, std::char_traits<char> >&) const'
main.o: In function `main':
/home/jbabb1/workspace/as2transition/src/main.cpp:136: undefined reference to `as2transition::TransitionFormatter::parseOption(char const*, bool)'
/home/jbabb1/workspace/as2transition/src/main.cpp:193: undefined reference to `as2transition::TransitionFormatter::help(std::basic_ostream<char, std::char_traits<char> >&, bool)'
collect2: ld returned 1 exit status
make[1]: *** [as2transition] Error 1
make[1]: Leaving directory `/home/jbabb1/workspace/as2transition/src'
make: *** [all] Error 2

The important lines seem to be

rm -f libas2transition.a
ar cru libas2transition.a
ranlib libas2transition.a

which seem indicate that Automake is not attaching any object files to the built library (this is further confirmed by the file size of libas2transition.a being 8 bytes following the compilation).

What am I doing wrong?

Also as a follow-up question, how would I make this library available to other projects in a larger build (which use nested configure.ac files).

Thanks!

Upvotes: 0

Views: 686

Answers (1)

Jack Kelly
Jack Kelly

Reputation: 18657

Here's your problem:

libas2transition_a_SOURCES = # <-- You forgot a '\'
    TransitionFormatter.re2c \
    TransitionPath.cpp \
    Timestep.cpp \
    Predicate.cpp \
    StringUtils.cpp

Which meant that automake saw an empty list of sources.

Upvotes: 1

Related Questions