"没有规则来制定目标"对于由另一个makefile

时间:2015-05-04 13:25:24

标签: c++ makefile

主makefile是这样的,因为你可以看到它调用子目录中的另外两个makefile:commbc

我知道我不会使用makefile快捷方式,例如一次处理所有cpp个文件,但请不要立即注意。

comm/makefile中有一条规则要comm/build/Communication.o,但我不知道如何将这个事实告诉主要的makefile。

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)

1 个答案:

答案 0 :(得分:0)

假设comm/Makefile知道如何正确构建该目标(make build/Communication.o目录中的comm有效);然后,如果你真的想让它正常工作(你可能不想这样做,请参阅Recursive Make Considered Harmful了解原因),你需要告诉顶级人员在这种情况下做什么。

这样的事情:

comm/build/%.o:
    @$(MAKE) -C comm $(patsubst comm/%,%,$@)