2013-04-15 95 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,我會在早上嘗試! –