2016-05-13 129 views
1

我对Ubuntu的,其文件夹结构是一些OpenCV的C++代码:不能编译,利用makefile

|-- bin 
| |-- camera-calib.o 
| `-- frontalize.o 
|-- docs 
| `-- notes.md 
|-- LICENSE.md 
|-- Makefile 
|-- README.md 
|-- shape_predictor_68_face_landmarks.dat 
`-- src 
    |-- calib 
    | |-- calib.cpp 
    | |-- calib.h 
    | |-- POSIT.cpp 
    | |-- POSIT.h 
    | |-- pro 
    | | |-- calib.o 
    | | |-- Makefile 
    | | |-- POSIT.o 
    | | |-- pro 
    | | |-- pro.pro 
    | | |-- pro.pro~ 
    | | `-- util.o 
    | `-- util 
    |  |-- calib_util.cpp 
    |  `-- calib_util.h 
    |-- camera-calib.cpp 
    |-- camera-calib.h 
    |-- check_resources.h 
    |-- fatialfeaturedetect.cpp 
    |-- frontalization-models 
    | |-- DataAlign2LFWa.mat 
    | |-- eyemask.mat 
    | `-- model3Ddlib.mat 
    |-- frontalize.cpp 
    |-- frontalize.h 
    `-- main.cpp 

我使用的Makefile文件是:

EXE = face_frontalization 
OBJ_DIR = bin 
CFLAGS = -g -w 

dummy_build_folder := $(shell mkdir -p $(OBJ_DIR)) 

# c++ source files of the project 
CXXFILES = $(shell find src -maxdepth 3 -type f -name '*.cpp') 
CXXOBJ = $(patsubst src/%.cpp,bin/%.o,$(CXXFILES)) 

INCLUDE = -I/usr/include/dlib-18.18 
LIBS = `pkg-config --libs opencv` 
CXXFLAGS = `pkg-config --cflags opencv` -w -Wall -Wextra -g -std=c++0x 
CFLAGS = `pkg-config --cflags opencv` -g -w 

ifdef V 
MUTE = 
VTAG = -v 
else 
MUTE = @ 
endif 

all: $(EXE) 
    # build successful 

$(EXE): $(CXXOBJ) 
    $(CXX) $(CXXOBJ) -o $(EXE) $(LIBS) 

$(OBJ_DIR)/%.o: src/%.cpp 
    $(CXX) $(CXXFLAGS) $(INCLUDE) $< -c -o [email protected] 
    $(BUILD) 

$(OBJ_DIR)/%.o: src/%.c 
    $(CC) $(CFLAGS) $(INCLUDE) $< -c -o [email protected] 

run: all 
    ./$(EXE) 

clean: 
    # Cleaning... 
    -rm -f $(EXE) $(CXXOBJ) 
    rmdir bin/ 

现在我得到这个错误:

6 of 7 
g++ `pkg-config --cflags opencv` -w -Wall -Wextra -g -std=c++0x -I/usr/include/dlib-18.18 src/calib/util/calib_util.cpp -c -o bin/calib/util/calib_util.o 
Assembler messages: 
Fatal error: can't create bin/calib/util/calib_util.o: No such file or directory 
make: *** [bin/calib/util/calib_util.o] Error 1 

我没有得到这个错误之前,所以不知道为什么它来了。该文件存在于目录中。我应该怎么做呢?

回答

1

它看起来像你的目录结构有点关闭。

can't create bin/calib/util/calib_util.o: No such file or directory

根据你的层次,你没有目录bincalib/util。尝试创建并再次运行make

+0

我可以在Makefile中添加一些代码,只需看到src文件夹结构就可以自动执行该代码吗? –

+0

看[这里](https://stackoverflow.com/questions/1950926/create-directories-using-make-file)。 – pushkin

+0

只有1个问题。是使用这条线的好方法:CXXFILES = $(shell找到src -maxdepth 3 -type f -name'* .cpp') 还是有更好的方法来做到这一点吗? –