makefile for opencv
test2.cpp:
#include <stdio.h> #include <opencv2/core/core.hpp>.h> #include <opencv2/highgui.hpp> int main() { IplImage * image=NULL; image = cvLoadImage("lena.jpg"); if( !image ) printf("loading error!\n"); else { cvNamedWindow("1"); cvShowImage("1", image); cvWaitKey(0); cvDestroyWindow("1"); } return 0; }
makefile:
CXXFLAGS:= $(shell pkg-config --cflags opencv)
LDLIBS:= $(shell pkg-config --libs opencv)
OBJS:= test2.o
all:test2
test2:$(OBJS)
g++ -o test2 $+ $(CXXFLAGS) $(LDLIBS)
%.o:%.cpp
g++ -c $+ $(CXXFLAGS)
clean:
rm -f *.o
这个自己测试的编译成功
2.4与3.0混版g++ok:
g++ -I/usr/include -I/usr/include/opencv -I/usr/include/opencv2 -o"MoveSense_Dvpu" test2.cpp /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgcodecs.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_shape.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_videoio.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so
这个也ok:
INCLUDES = -I /usr/local/include LIBS +=-lm -lstdc++ -L /usr/local/lib/libopencv_calib3d.so \ /usr/local/lib/libopencv_core.so\ /usr/local/lib/libopencv_features2d.so \ /usr/local/lib/libopencv_flann.so \ /usr/local/lib/libopencv_highgui.so \ /usr/local/lib/libopencv_imgcodecs.so \ /usr/local/lib/libopencv_imgproc.so \ /usr/local/lib/libopencv_ml.so \ /usr/local/lib/libopencv_objdetect.so \ /usr/local/lib/libopencv_photo.so \ /usr/local/lib/libopencv_shape.so \ /usr/local/lib/libopencv_stitching.so \ /usr/local/lib/libopencv_superres.so \ /usr/local/lib/libopencv_videoio.so \ /usr/local/lib/libopencv_video.so \ /usr/local/lib/libopencv_videostab.so OBJS:= test2.o #OBJS:= ./main/main_dsst.o all:test2 test2:$(OBJS) g++ -o test2 $+ $(LIBS) $(INCLUDES) %.o:%.cpp g++ -c $+ $(INCLUDES) clean: rm -f *.o test2
这一版也可以:
#这里需要根据自己在linux上配置的opencv路径修改 INCLUDES = -I /usr/local/include LIBS +=-lm -lstdc++ -L/usr/local/lib/libopencv_calib3d.so \ /usr/local/lib/libopencv_core.so\ /usr/local/lib/libopencv_features2d.so \ /usr/local/lib/libopencv_flann.so \ /usr/local/lib/libopencv_highgui.so \ /usr/local/lib/libopencv_imgcodecs.so \ /usr/local/lib/libopencv_imgproc.so \ /usr/local/lib/libopencv_ml.so \ /usr/local/lib/libopencv_objdetect.so \ /usr/local/lib/libopencv_photo.so \ /usr/local/lib/libopencv_shape.so \ /usr/local/lib/libopencv_stitching.so \ /usr/local/lib/libopencv_superres.so \ /usr/local/lib/libopencv_videoio.so \ /usr/local/lib/libopencv_video.so \ /usr/local/lib/libopencv_videostab.so # LIBS = -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml # LIBDIRS = -L/usr/local/lib OPT = -O3 -Wno-deprecated CC=g++ .PHONY: all clean OBJS= test2.o clean: rm -f *.o *~ test2 all:test2 echo all:make complete test2:$(OBJS) #$(CC) $(LIBDIRS) $(LIBS) -o $@ $+ $(OPT) $(CC) $(OPT) $(INCLUDES) $+ $(LIBS) -o $@ #$@代表冒号后面的依赖项 $+代表冒号前面的目标,目标一定要放在libs的前面 %.o:%.cpp $(CC) -c $(INCLUDES) $+
注意:如果报错:Makefile:1: *** missing separator. Stop.
原因:
makefile里不要乱用TAB,命令所在行才能且只能以TAB开头
其他的如,make变量的定义、赋值,make内定函数如$(error "strings")都不能以TAB开头,不然make会将其作为命令来处理
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/56287507
- 点赞
- 收藏
- 关注作者
评论(0)