一种调用opencv库的C++工程通用的Makefile模板

时间:2022-11-03 21:05:47

第一次自己写makefile,记录一下

#Compilers
#CXX=/opt/compiler/gcc-4.8./bin/g++
CXX = g++ #Includes
INCLUDE_FLAGS = -I${OPENCV_PATH}/include/ #Libraries
LIB_FLAGS = -L${OPENCV_PATH}/lib/ #DLLs
LD_FLAGS = -lopencv_objdetect -lopencv_highgui -ljasper -ljpeg -ltiff -lpng -lopencv_features2d -lopencv_flann -lopencv_imgproc -lopencv_core -lz -lrt -ldl -lm -lpthread -lstdc++ -fopenmp #CPP Flags
CPP_FLAGS = -O3 -W -Wall -msse -msse2 -msse3 -msse4. -fopenmp #EXES
EXE_ExamReg = ExamReg
SO_ExamReg = ExamReg.so #Files
FILES = ExamReg.o ChoiceRecModule.o Convert.o ExamException.o Gradient.o Historgram.o MLSVM.o PoseAlignModule.o stringfunc.o #Tasks
all: ${EXE_ExamReg} ${SO_ExamReg} ${EXE_ExamReg}: ${FILES}
${CXX} ${CPP_FLAGS} $^ -o $@ ${INCLUDE_FLAGS} ${LIB_FLAGS} ${LD_FLAGS} ${SO_ExamReg}: $(FILES)
${CXX} ${CPP_FLAGS} $^ -shared -fPIC -o $@ ${INCLUDE_FLAGS} ${LIB_FLAGS} ${LD_FLAGS} #FILE_CC
%.o : %.cpp
${CXX} ${CPP_FLAGS} -c $< -o $@ ${INCLUDE_FLAGS} #Clean
clean:
rm -f *.o
rm -f ${EXE_ExamReg}
rm -f ${SO_ExamReg} #Auto build done