Question

I am building a shared library, and have a source tree structured like this:

Makefile.am
src/
    Makefile.am
    srcfile1.h
    srcfile1.cpp
    ...
thirdpaty/
    Makefile.am
    lib1/
        Makefile.am
        lib1.h
        lib1.cpp
        ...
    lib2/
        ...

I use recursive Automake since some of the third party libraries are distributed with their own Automake files. src/Makefile.am includes the usual libtool macros:

lib_LTLIBRARIES = libmylib.la 
libmylib_la_SOURCES = scrfile1.h srcfile1.cpp ...

How do I link the main library to the third party ones? The Autotools manual leads me to believe that the third party libraries needs to be built as libtool convenience libraries, so I have the following in thirdparty/lib1/Makefile.am:

noinst_LTLIBRARIES  = libthirdpaty1.la
libthirdpaty1_la_SOURCES = lib1.cpp lib1.h

And add the following in src/Makefile.am:

libmylib_la_LIBADD = $(top_buildir)/thirdparty/lib1/libthirdpaty1.la

My root Makefile.am holds the INCLUDES macro:

INCLUDES = -I$(top_builddir)/thirdparty

But building with this configuration gives me undefined symbol errors.

What is the correct way to structure this source code and link all the libraries together?

Was it helpful?

Solution

It turns out that that source layout and libtool usage were fine, but my root Makefile.am had the following macro:

SUBDIRS = src thirdparty

Which should have been

SUBDIRS = thirdparty src

Since the code in src/ referenced the code in thirdparty/, the thirdparty/ code needed to be built first. The SUBDIRS macro causes subfolders to be built in the order they are specified, from left to right.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top