我正在尝试使用ubuntu中的makefile编译我的c ++程序但是有一个我无法理解的错误。这是我收到的错误消息。
Parallel/ParallelSlave.o Parallel/IOHandler.o commons/File19794.o -o bin/genericMatching
/usr/bin/ld: cannot open output file bin/genericMatching: No such file or directory
collect2: error: ld returned 1 exit status
Makefile:38: recipe for target 'bin/genericMatching' failed
这是我的Makefile中的代码,我的程序文件夹中没有bin文件/目录:
# The compiler to use.
CC = mpiCC
# Directories for Includes and Common clases
IDIR =include
CDIR =commons/
JIANGDIR =MatcherJiang/
MCCDIR =MCC/
PDIR =Parallel/
BINDIR =bin/
# Compiler options -Weffc++
CFLAGS= -Wall -O2 -fopenmp -I$(IDIR) -I$(JIANGDIR) -I$(MCCDIR)
# Sources and Common clases sources
SOURCES= $(PDIR)genericMatching.cpp
SOURCESD= $(PDIR)DPDDFF.cpp
CSOURCES= $(CDIR)Fingerprint.cpp $(CDIR)Score.cpp $(JIANGDIR)FingerprintJiang.cpp $(MCCDIR)MCC.cpp $(MCCDIR)Cylinder.cpp $(CDIR)Functions.cpp $(CDIR)Minutia.cpp $(CDIR)GrahamScanConvexHull.cpp $(CDIR)Munkres.cpp $(PDIR)ParallelHandler.cpp $(PDIR)ParallelMaster.cpp $(PDIR)ParallelSlave.cpp $(PDIR)IOHandler.cpp $(CDIR)File19794.cpp
# Objects
OBJECTS=$(SOURCES:.cpp=.o)
OBJECTSD=$(SOURCESD:.cpp=.o)
COBJECTS=$(CSOURCES:.cpp=.o)
# Name of the executable
EXECUTABLE=$(BINDIR)genericMatching
EXECUTABLED=$(BINDIR)DPDDFF
all: $(EXECUTABLE) $(EXECUTABLED)
.PHONY: doc
doc:
doxygen Doxyfile
$(EXECUTABLE): $(OBJECTS) $(COBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) $(COBJECTS) $(OBJECTFILES) -o $@ $(LDFLAGS)
$(EXECUTABLED): $(OBJECTSD) $(COBJECTS)
$(CC) $(CFLAGS) $(OBJECTSD) $(COBJECTS) $(OBJECTFILES) -o $@ $(LDFLAGS)
.cpp.o:
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f $(OBJECTS) $(OBJECTSD) $(COBJECTS) $(EXECUTABLE) $(EXECUTABLED)
mrproper: clean
rm -r doc/latex doc/html
答案 0 :(得分:1)
运行此规则时:
$(EXECUTABLE): $(OBJECTS) $(COBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) $(COBJECTS) $(OBJECTFILES) -o $@ $(LDFLAGS)
它会隐式运行ld
来创建$(EXECUTABLE)
,即bin/genericMatching
。由于bin目录不存在,因此抛出错误。我建议添加:
$(EXECUTABLE) $(EXECUTABLED): | $(BIN)
$(BIN) :
mkdir -p $@
到你的makefile。 Make将在构建可执行文件之前生成目录。请注意,|
使其成为order-only先决条件,这意味着如果$(EXECUTABLE)
比任一目标更新,则不会重建$(EXECUTABLED)
或$(BIN)
。