0

我试图让 dlib 库从过去两周开始在我的 C++ 项目中工作,并找到了一些解决方案,但我仍然面临着我无法理解的错误。因为我是 makefile 的新手,dlib 指导我如何处理 makefile。

文件夹结构是这样的:

projectDir
|-makefile
|-src
   |-CDetector.cpp
   |-CDetectot.h
   |-CStreamReader.cpp
   |-CStreamReader.h
|-include
   |-darknet
      |-(files).h (other .h files needed by src files)
   |-dlib-19.6
      |-all
         |-source.cpp
      |-lots of header files
      |-...
|-external_libs
   |-libdarknet.a
   |-libdarknet.so

生成文件如下所示:

EXE = darknet

OBJ_DIR = obj

CXXFILES = $(shell find src -type f -name '*.cpp')

CXXOBJ = $(patsubst src/%.cpp,obj/%.o,$(CXXFILES))

INCLUDE = -I/include -I/include/darknet

LIBS = external_libs/libdarknet.a

CXXFLAGS = `pkg-config --cflags-only-I opencv` -Wall -Wno-unknown-pragmas -Wfatal-errors -Wwrite-strings -fPIC

LDFLAGS = -lm -pthread -lX11 -DDLIB_JPEG_SUPPORT -ljpeg

all: $(EXE)

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

$(OBJ_DIR)/%.o: src/%.cpp
    $(CXX) $(CXXFLAGS) $(INCLUDE) $< -c -o $@
    $(BUILD)


run: all
    ./$(EXE)

clean:
        -rm -f $(EXE) $(CXXOBJ)
    rmdir obj/
4

1 回答 1

0

它需要一些修改,因为 INCLUDE、CXXFLAGS 和 LDFLAGS 将是

INCLUDE = -Iinclude -Iinclude/darknet `pkg-config --cflags-only-I opencv`
CXXFLAGS = -Wall -Wno-unknown-pragmas -Wfatal-errors -Wwrite-strings -fPIC 
LDFLAGS = -lm -pthread -lX11 -DDLIB_JPEG_SUPPORT -ljpeg -lopencv_videoio `pkg-config --libs opencv`

我现在正在使用暗网 makefile 来做到这一点,所以我的 makefile 看起来像

VPATH = ./src/
ALIB = external_libs/libdarknet.a
EXEC = darknet
OBJDIR = ./obj/

CC = g++ -std=c++11
NVCC = nvcc 
AR = ar
ARFLAGS = rcs
OPTS = -Ofast

LDFLAGS = -lm -pthread -lX11 -DDLIB_JPEG_SUPPORT -ljpeg -lopencv_videoio `pkg-config --libs opencv`

INCLUDE = -Iinclude -Iinclude/darknet `pkg-config --cflags-only-I opencv`

CFLAGS = -Wall -Wno-unknown-pragmas -Wfatal-errors -Wwrite-strings -fPIC

OBJ = CDetector.o CStreamReader.o

EXECOBJA = CDetector.o CStreamReader.o

EXECOBJ = $(addprefix $(OBJDIR), $(EXECOBJA))
OBJS = $(addprefix $(OBJDIR), $(OBJ))
DEPS = $(wildcard src/*.h) Makefile include/darknet/darknet.h

all: obj results $(ALIB) $(EXEC)

$(EXEC): $(EXECOBJ) $(ALIB)
    $(CC) $(INCLUDE) $(CFLAGS) $^ -o $@ $(LDFLAGS) $(ALIB)

$(ALIB): $(OBJS)
    $(AR) $(ARFLAGS) $@ $^

$(OBJDIR)%.o: %.cpp $(DEPS)
    $(CC) $(INCLUDE) $(CFLAGS) -c $< -o $@

obj:
    mkdir -p obj
backup:
    mkdir -p backup
results:
    mkdir -p results

.PHONY: clean

clean:
    rm -rf $(OBJS) $(ALIB) $(EXEC) $(EXECOBJ)
于 2018-02-26T09:29:24.917 回答