简体   繁体   中英

include DLIB and other header files in C++ project

I'm trying to get dlib library working in my C++ project from last 2 weeks and found some solution but still i'm facing errors which i can not understand. As i am newbie to the makefile and dlib guide me what to do with makefile.

The folder structure is like this:

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

The makefile looks like this:

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/

It needs some modification as INCLUDE, CXXFLAGS AND LDFLAGS will be

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`

and i'm now using darknet makefile to do it so my makefile looks like

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM