我正在尝试使用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"
文件仅用于构建过程。
谢谢
答案 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