2013-04-15 55 views
2

我正在尝试自动工具。我有以下的项目层次:autotools:一个项目包含一个可执行文件,一个共享obj和一个“共享”内部库

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

之前你太深入到自动工具,我建议考虑看看CMake的。与autotools相比,我发现使用起来要容易得多。但是,如果您以传统风格制作开源软件,那么预计会有autotools。 –

回答

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应该orderSUBDIRS使依赖先建:

SUBDIRS = utilities executable sharedObject

+0

谢谢Brett,我会在早上尝试! –