makefile opencv的案例

Posted ZONG_XP

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了makefile opencv的案例相关的知识,希望对你有一定的参考价值。

 案例一

CXX = g++
LIBS +=`pkg-config --libs opencv`
INC +=`pkg-config --cflags opencv`
CPPFLAGS += -g -std=c++11 -Wall

SRCS = detect.cpp
TARGET = detect
OBJS = detect.o

$(TARGET):$(OBJS)
    $(CXX) $(INC) $(CPPFLAGS) $(OBJS) -o $(TARGET) $(LIBS)
$(OBJS):%.o:%.cpp
    $(CXX) $(INC) $(CPPFLAGS) -c $< -o $@

.PHONY:clean
clean:
    rm -r *.o $(TARGET)

案例二

CXX = g++
LDLIBS += `pkg-config --libs opencv`
INC += `pkg-config --cflags opencv`
CPPFLAGS += -g -std=c++11 -Wall -I./

TARGET = edges
OBJS = edges.o label.o
SRCS = edges.cpp label.cpp
HEAD = label.hpp

$(TARGET):$(OBJS)
    $(CXX) -o $(TARGET) $(OBJS) $(LDLIBS)

%.o:%.c $(HEAD)
    $(CXX) $(INC) $(CPPFLAGS) -c $> -o $@

.PHONY:clean
clean:
    rm -r *.o

案例三

CXX = g++
INC += `pkg-config --cflags opencv`
LIBS += `pkg-config --libs opencv`


#dir
DIR_INC = ./include
DIR_SRC = ./src
DIR_OBJ = ./obj
DIR_BIN = ./bin

CPPFLAGS += -g -std=c++11 -Wall -I$DIR_INC

#SRC = $(wildcard $DIR_SRC/*.cpp)
SRC1 = $DIR_SRC/detect.cpp $DIR_SRC/tools.cpp
OBJ1 = $(patsubst %.cpp,$DIR_OBJ/%.o,$(notdir $SRC1))
BIN_TARGET1 = $DIR_BIN/detect

SRC2 = $DIR_SRC/detect2.cpp $DIR_SRC/tools.cpp
OBJ2 = $(patsubst %.cpp,$DIR_OBJ/%.o,$(notdir $SRC2))
BIN_TARGET2 = $DIR_BIN/detect2

SRC3 = $DIR_SRC/detect_circle.cpp $DIR_SRC/tools.cpp
OBJ3 = $(patsubst %.cpp,$DIR_OBJ/%.o,$(notdir $SRC3))
BIN_TARGET3 = $DIR_BIN/detect_circle

SRC4 = $DIR_SRC/detect_circle2.cpp $DIR_SRC/tools.cpp
OBJ4 = $(patsubst %.cpp,$DIR_OBJ/%.o,$(notdir $SRC4))
BIN_TARGET4 = $DIR_BIN/detect_circle2

SRC5 = $DIR_SRC/hog_svm_test.cpp $DIR_SRC/tools.cpp
OBJ5 = $(patsubst %.cpp,$DIR_OBJ/%.o,$(notdir $SRC5))
BIN_TARGET5 = $DIR_BIN/hog_svm_test

SRC6 = $DIR_SRC/hog_svm_test2.cpp $DIR_SRC/tools.cpp
OBJ6 = $(patsubst %.cpp,$DIR_OBJ/%.o,$(notdir $SRC6))
BIN_TARGET6 = $DIR_BIN/hog_svm_test2

SRC7 = $DIR_SRC/hog_svm_test2.cpp $DIR_SRC/tools.cpp
OBJ7 = $(patsubst %.cpp,$DIR_OBJ/%.o,$(notdir $SRC7))
BIN_TARGET7 = $DIR_BIN/hog_svm_test3

detect:$BIN_TARGET1

detect2:$BIN_TARGET2

detect_circle:$BIN_TARGET3

detect_circle2:$BIN_TARGET4

hog_svm_test:$BIN_TARGET5

hog_svm_test2:$BIN_TARGET6

hog_svm_test3:$BIN_TARGET7

# echo:
#     echo $(OBJ1)
#     echo $(BIN_TARGET)
#     echo $(notdir $SRC1)

$BIN_TARGET1:$OBJ1
    $(CXX) -o $@  $(OBJ1)  $(LIBS)

$BIN_TARGET2:$OBJ2
    $(CXX) -o $@  $(OBJ2)  $(LIBS)

$BIN_TARGET3:$OBJ3
    $(CXX) -o $@  $(OBJ3)  $(LIBS)

$BIN_TARGET4:$OBJ4
    $(CXX) -o $@  $(OBJ4)  $(LIBS)

$BIN_TARGET5:$OBJ5
    $(CXX) -o $@  $(OBJ5)  $(LIBS)

$BIN_TARGET6:$OBJ6
    $(CXX) -o $@  $(OBJ6)  $(LIBS)

$BIN_TARGET7:$OBJ7
    $(CXX) -o $@  $(OBJ7)  $(LIBS)


$DIR_OBJ/%.o:$DIR_SRC/%.cpp
    $(CXX)  $(CPPFLAGS) -c  $< -o $@


.PHONY:clean
clean:
    find $DIR_OBJ -name *.o -exec rm -rf  \\;

以上是关于makefile opencv的案例的主要内容,如果未能解决你的问题,请参考以下文章

makefile opencv的案例

用于链接OpenCV和现有库的Makefile(不使用cmake)

为opencv项目创建一个makefile

在ubuntu中用cuda编译opencv的makefile停止工作

linux下怎样编译opencv文件

[opencv学习笔记] jiazhigang 30讲源码C++版本(含Makefile)