Reputation: 707
Recently I've been trying to add dlib library to my project (I am interested in MPC part since I want it to control a quadrocopter), despite many different approaches I couldn't find a proper working solution. I have a makefile like this:
all : quadro_mini
CXXFLAGS = -std=c++11 -lpthread -O3 #-Wall -pedantic
LIBRARIES = -IMPU6050 -LMPU6050 -IHCSR04 -LHCSR04
OBJS = Steer.o Measurer.o LogWriter.o Server.o Functions.o Engine.o EnginesManager.o main.o
HDRS = Server.h Measurer.h LogWriter.h Functions.h SteeringSignalsListener.h Engine.h EnginesManager.h Constants.h Steer.h
$(OBJS) : $(HDRS)
quadro_mini : $(OBJS)
g++ -pthread $^ $(LIBRARIES) -lMPU6050 -lHCSR04 -DLIB_NO_GUI_SUPPORT -o $@
I want to use dlib in Steer.o module
First approach
Linking to header containing all necessary includes
OBJS = Measurer.o LogWriter.o Server.o Functions.o Engine.o EnginesManager.o main.o dlib/control.o #nazwy sie musza zgadzac z nazwami *.cpp i *.h
HDRS = Server.h Measurer.h LogWriter.h Functions.h SteeringSignalsListener.h Engine.h EnginesManager.h Constants.h Steer.h
$(OBJS) : $(HDRS)
Steer.o : $(HDRS)
g++ $(CXXFLAGS) $^ $(LIBRARIES) -I. dlib/control.h -o $@
quadro_mini : $(OBJS) Steer.o
g++ -pthread $^ $(LIBRARIES) -lMPU6050 -lHCSR04 -DLIB_NO_GUI_SUPPORT -o $@
The output I receive:
In file included from dlib/control/../matrix/matrix_exp.h:6:0,
from dlib/control/../matrix/matrix.h:6,
from dlib/control/../matrix.h:6,
from dlib/control/approximate_linear_models.h:7,
from dlib/control/lspi.h:7,
from dlib/control.h:6,
from Steer.h:10:
dlib/control/../matrix/../algs.h:146:9: error: expected identifier before numeric constant
dlib/control/../matrix/../algs.h:146:9: error: expected '}' before numeric constant
dlib/control/../matrix/../algs.h:146:9: error: expected unqualified-id before numeric constant
dlib/control/../matrix/../algs.h:495:14: error: expected nested-name-specifier before 'disable_if_c'
dlib/control/../matrix/../algs.h:495:26: error: expected initializer before '<' token
dlib/control/../matrix/../algs.h:510:14: error: expected nested-name-specifier before 'enable_if_c'
dlib/control/../matrix/../algs.h:510:25: error: expected initializer before '<' token
dlib/control/../matrix/../algs.h:627:48: error: 'uint64' was not declared in this scope
dlib/control/../matrix/../algs.h:627:48: note: suggested alternative:
etc.
Second aproach:
Making library out of it
all: dlib.a
CXXFLAGS = -Wall -g -std=c++11 -pthread -DLIB_NO_GUI_SUPPORT
dlib.o : control.h
g++ $(CXXFLAGS) -c $^ -o $@
dlib.a: dlib.o
ar -rv $@ $^
But since everything is header in dlib then what header should I include ? None... since official page forbids from adding it to compiler's include path. Then this approach still doesn't work... just for info - compile artifacts take over 60 mb.
Third approach
Adding the folder that contains the dlib folder to include search path and then use include statements of the form #include (dlib official statement).
CPLUS_INCLUDE_PATH=/home/linaro/Quadrocopter/dlib
export CPLUS_INCLUDE_PATH
Also
CPLUS_INCLUDE_PATH=/home/linaro/Quadrocopter/
export CPLUS_INCLUDE_PATH
First gives:
/home/linaro/Quadrocopter/dlib/dlib_include_path_tutorial.txt:1:2: error: #error "Don't put the dlib folder in your include path"
etc.
Second has similar effect as First Approach
I've also created test build with only 2 compilation artifacts:
all : test
CXXFLAGS = -g -O3 -std=c++11
LFLAGS = -lpthread -lnsl
OBJS = maintest.o LogWriter.o
HDRS = LogWriter.h Constants.h
$(OBJS) : $(HDRS)
test : $(OBJS)
g++ -pthread -Idlib/control.h $^ -o $@
And this is working ! Yet it cannot with my previous makefile
Anyone please help me with this ? (and no -Ldlib is also not working)
Environment: Custom Lubuntu, gcc version 4.7.2, GNU Make 3.81
Upvotes: 1
Views: 815
Reputation: 99172
Let us proceed in small steps. Try this, and tell us the result:
HDRS = Server.h Measurer.h LogWriter.h Functions.h SteeringSignalsListener.h Engine.h EnginesManager.h Constants.h Steer.h
Measurer.o : Measurer.cpp $(HDRS)
g++ $(CXXFLAGS) $< -I. -o $@
Upvotes: 1