2015-05-04 56 views
1

主makefile就是這樣,你可以看到它調用了子目錄中的其他兩個makefile:commbc「另一個makefile創建的目標無目標」

我知道我不使用makefile快捷方式,像立即處理所有cpp文件,但請不要立即關注。

comm/makefile有一個規則,使comm/build/Communication.o,但不知何故我不知道如何將這一事實告訴主要的生成文件。

CPPFLAGS=-g -c --std=c++11 -Iinc -I/usr/include -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I/usr/include/boost -Ibc/inc -Icomm/inc 
LDFLAGS=-g -L/usr/lib/x86_64-linux-gnu/ -lQt5Core -lboost_system -lpthread -lboost_thread 

all: comm/bin/party bc/bin/bctest bin/protocol 

comm/bin/party: 
    cd comm && $(MAKE) 

bc/bin/bctest: 
    cd bc && $(MAKE) 

bin/protocol:build/main.o \ 
      build/TrustedParty.o \ 
      build/Player.o \ 
      build/utils.o \ 
      comm/build/Communication.o \ 
      comm/build/FileParser.o \ 
      comm/build/Party.o \ 
      comm/build/PeerConnection.o \ 
      comm/build/ServerModule.o \ 
      comm/build/Utilities.o \ 
      bc/build/BooleanCircuit.o \ 
      bc/build/Gate.o \ 
      bc/build/Wire.o 
    g++ -Wall $^ -o bin/protocol $(LDFLAGS) 


build/main.o:src/main.cpp 
    g++ $(CPPFLAGS) -fPIC src/main.cpp -o build/main.o 

build/TrustedParty.o:src/TrustedParty.cpp 
    g++ $(CPPFLAGS) src/TrustedParty.cpp -o build/TrustedParty.o 

build/Player.o:src/Player.cpp 
    g++ $(CPPFLAGS) src/Player.cpp -o build/Player.o 

build/utils.o:src/utils.cpp 
    g++ $(CPPFLAGS) src/utils.cpp -o build/utils.o 

clean: 
    rm -fr build/* bin/* 
    rm -fr comm/build/* bin/* 
    rm -fr bc/build/* bin/* 

當我運行make返回

16:15:03 **** Build of configuration Default for project bmr **** 
make all 
g++ -g -c --std=c++11 -Iinc -I/usr/include -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I/usr/include/boost -Ibc/inc -Icomm/inc -fPIC src/main.cpp -o build/main.o 
g++ -g -c --std=c++11 -Iinc -I/usr/include -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I/usr/include/boost -Ibc/inc -Icomm/inc src/TrustedParty.cpp -o build/TrustedParty.o 
g++ -g -c --std=c++11 -Iinc -I/usr/include -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I/usr/include/boost -Ibc/inc -Icomm/inc src/Player.cpp -o build/Player.o 
g++ -g -c --std=c++11 -Iinc -I/usr/include -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I/usr/include/boost -Ibc/inc -Icomm/inc src/utils.cpp -o build/utils.o 
make: *** No rule to make target `comm/build/Communication.o', needed by `bin/protocol'. Stop. 

16:15:11 Build Finished (took 7s.821ms) 

回答

0

假設comm/Makefile知道如何實現(在comm目錄作品make build/Communication.o),其目標正確;那麼如果你真的想讓這個工作正常(你可能不想,請看Recursive Make Considered Harmful爲什麼),你需要告訴頂層在這種情況下做什麼。

事情是這樣的:

comm/build/%.o: 
    @$(MAKE) -C comm $(patsubst comm/%,%,[email protected]) 
+0

如何讓它擺在首位的正確方法是什麼建議嗎? (不添加修補程序..) – Bush

+0

不涉及這種修復的問題的解決方案是停止使用遞歸make並開始使用非遞歸make系統。我還沒有讀過它,但作者知道他的東西,所以[this](http://www.cmcrossroads.com/article/painless-non-recursive-make)在這裏可能有一些幫助,但總體思路是你只有一個make整個構建過程。 –