makefile for opencv

举报
风吹稻花香 发表于 2021/06/05 01:03:20 2021/06/05
【摘要】 test2.cpp: #include <stdio.h> #include <opencv2/core/core.hpp>.h> #include <opencv2/highgui.hpp> int main() { IplImage * image=NULL; image = cvLoadImage("lena.jpg...

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

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。