在 C++ 项目中包含 DLIB 和其他头文件

include DLIB and other header files in C++ project

我试图让 dlib 库在我的 C++ 项目中工作,从过去的 2 周开始,我找到了一些解决方案,但我仍然面临我无法理解的错误。由于我是 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/

它需要一些修改,因为 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`

我现在使用 darknet 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)