2

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?

4

1 回答 1

0

事实证明,源布局和 libtool 的使用都很好,但我的根 Makefile.am 有以下宏:

SUBDIRS = src thirdparty

应该是哪个

SUBDIRS = thirdparty src

由于 中的代码src/引用了 中的代码thirdparty/,因此thirdparty/需要先构建代码。该SUBDIRS宏使子文件夹按照指定的顺序从左到右构建。

于 2013-08-25T22:21:24.423 回答