2010-05-04 50 views
0

我正在使用Solaris 10,Sun Studio 11.我正在重構一些舊代碼,並嘗試爲它們編寫單元測試。我的make文件看起來像:在將文件鏈接到最終可執行文件之前將文件合併到單個目錄中

my_model.o:my_model.cc 
    CC -c my_model.cc -I/../../include -library=stlport4 -instances=extern 

unit_test: unit_test.o my_model.o symbol_dictionary.o 
    CC -o unit_test unit_test.o my_model.o symbol_dictionary.o -I../../include \ 
    -library=stlport4 -instances=extern 

unit_test.o: unit_test.cc 
    CC -c unit_test.cc -I/../../include -library=stlport4 -instances=extern 

symbol_dictionary.o: 
    cd ../../test-fixtures && ($MAKE) symbol_dictionary.o 
    mv ../../test-fixtures/symbol_dictionary.o . 

在../../test-fixtures生成文件,我有以下目標:

symbol_dictionary.o: 
    CC -c symbol_dictionary.cc -I/../../include -library=stlport4 -instances=extern 

我做的情況下=的extern,因爲我已經連接問題之前,這是推薦的解決方案。結果是在每個正在編譯的目錄中,創建一個SunWS_Cache目錄來存儲模板實例。

這是解決這個問題的很長的路要走。在鏈接它們之前,將目標文件合併到一個目錄中是否是標準做法?

回答

1

簡答:這是一種常見的做法,常常方便,不總是好,並不總是壞。

而且,你的makefile文件可以短和更清潔的,如果你使用的自動變量和模式的規則:

COMPILE = CC -I/../../include -library=stlport4 -instances=extern 

%.o: %.cc 
    $(COMPILE) -c $< 

unit_test: unit_test.o my_model.o symbol_dictionary.o 
    $(COMPILE) -o [email protected] $^ 

symbol_dictionary.o: 
    cd ../../test-fixtures && ($MAKE) [email protected] 
    mv ../../test-fixtures/[email protected] . 
在../../test

COMPILE = CC -I/../../include -library=stlport4 -instances=extern 

symbol_dictionary.o: %.o : %.cc 
    $(COMPILE) -c $< 
相關問題