autotools:一个项目包含一个可执行文件,一个共享obj和一个“共享”内部库

时间:2013-04-15 21:43:38

标签: c autotools libtool

我正在尝试使用autotools。我有以下项目层次结构:

    project/src
    project/src/utilities
    project/src/utilities/util.c
    project/src/utilities/util.h
    project/src/sharedObject
    project/src/sharedObject/sharedObject.c
    project/src/sharedObject/sharedObject.h
    project/src/sharedObject/thing.c
    project/src/executable
    project/src/executable/exec.c
    project/src/executable/exec.h
    project/src/executable/thing1.c
    project/src/executable/thing2.c

"executable""sharedObject.so"都取决于"util.o""util.h"。我已经看到了创建便捷库的示例,但我不确定如何在其他两个子项目的"Makefile.am"文件中指定它们。如何定义这些项目间的依赖关系?

将安装"executable""sharedObject.so""util.o""util.h"文件仅用于构建过程。

谢谢

1 个答案:

答案 0 :(得分:2)

utilities/Makefile.am

noinst_LTLIBRARIES = libutil.la   
libutil_la_SOURCES = util.h util.c

executable/Makefile.am中,库的使用应使用LDADD主要内容,例如,

bin_PROGRAMS = exec
exec_SOURCES = exec.h exec.c thing.h thing.c
exec_LDADD = ../utilities/libutil.la

sharedObject/Makefile.am中,使用LIBADD主要:

lib_LTLIBRARIES = sharedObject.la
sharedObject_la_SOURCES = sharedObject.h sharedObject.c thing.c
sharedObject_la_LIBADD = ../utilities/libutil.la

如果您确实想要动态加载sharedObject.so,还需要:

sharedObject_la_LDFLAGS = -module

否则,应该将目标称为libsharedObject


顶级Makefile.am应该order SUBDIRS,以便首先构建依赖项:

SUBDIRS = utilities executable sharedObject