VS2013+opencv2.4.10静态链接方式创建方法
Posted yuanzhijing
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VS2013+opencv2.4.10静态链接方式创建方法相关的知识,希望对你有一定的参考价值。
用VS2013+opencv2.4.10写的程序,想要你的程序在一台裸奔的电脑上运行,该怎么办?我自己上网查了,然后尝试了下,成功了,于是想分享给大家~
首先说下,我们平时在VS2013上使用opencv库函数的时候,基本都是以动态链接的方式调用,想要脱离自己的电脑到别的电脑上运行,就要把一堆.lib及.dll文件也一起拷过去,还不一定能成功,很费劲,现在跟大家分享下静态链接的方式。
我的opencv放在:D:\\Program Files\\,下面的路径前面的改为你们自己的路径就好,这个配置过的是知道的,新手要注意下。
1.配置环境变量:右击我的电脑-属性-高级系统设置-环境变量
用户变量新建opencv和PATH两个变量:
opencv: D:\\Program Files\\opencv\\build
PATH: D:\\Program Files\\opencv\\build\\x86\\vc12\\bin
系统变量Path要加一路径:D:\\Program Files\\opencv\\build\\x86\\vc12\\bin
注意中间用(英文的分号);隔开
2.打开VS2013中项目文件的属性管理器,如下界面:
包含目录:
D:\\Program Files\\opencv\\build\\include
D:\\Program Files\\opencv\\build\\include\\opencv2
D:\\Program Files\\opencv\\build\\include\\opencv
库目录:(注意这里和动态链接有区别)
D:\\Program Files\\opencv\\build\\x86\\vc12\\staticlib
(debug和release都分别配置下,下图是Debug属性页)
C/C++—代码生成—运行库:静态debug-/MTd ,静态release-/MT
连接器-输入-附加依赖项:
这里有两种方法,
一是附加依赖项添加opencv静态库文件:
Debug对应添加:
vfw32.lib
comctl32.lib
IlmImfd.lib
libjasperd.lib
libjpegd.lib
libpngd.lib
libtiffd.lib
zlibd.lib
opencv_ml2410d.lib
opencv_calib3d2410d.lib
opencv_contrib2410d.lib
opencv_core2410d.lib
opencv_features2d2410d.lib
opencv_flann2410d.lib
opencv_gpu2410d.lib
opencv_highgui2410d.lib
opencv_imgproc2410d.lib
opencv_legacy2410d.lib
opencv_objdetect2410d.lib
opencv_ts2410d.lib
opencv_video2410d.lib
opencv_nonfree2410d.lib
opencv_ocl2410d.lib
opencv_photo2410d.lib
opencv_stitching2410d.lib
opencv_superres2410d.lib
opencv_videostab2410d.lib
Release对应添加:
vfw32.lib
comctl32.lib
IlmImf.lib
libjasper.lib
libjpeg.lib
libpng.lib
libtiff.lib
zlib.lib
opencv_ml2410.lib
opencv_calib3d2410.lib
opencv_contrib2410.lib
opencv_core2410.lib
opencv_features2d2410.lib
opencv_flann2410.lib
opencv_gpu2410.lib
opencv_highgui2410.lib
opencv_imgproc2410.lib
opencv_legacy2410.lib
opencv_objdetect2410.lib
opencv_ts2410.lib
opencv_video2410.lib
opencv_nonfree2410.lib
opencv_ocl2410.lib
opencv_photo2410.lib
opencv_stitching2410.lib
opencv_superres2410.lib
opencv_videostab2410.lib
二是,附加依赖项不添加:
但是要建立个头文件(或者直接在主函数里),加入以下命令:
#ifdef _DEBUG
#pragma comment( lib, "IlmImfd.lib")
#pragma comment( lib, "libjasperd.lib")
#pragma comment( lib, "libjpegd.lib")
#pragma comment( lib, "libpngd.lib")
#pragma comment( lib, "libtiffd.lib")
#pragma comment( lib, "zlibd.lib")
#pragma comment( lib, "opencv_calib3d2410d.lib" )
#pragma comment( lib, "opencv_contrib2410d.lib" )
#pragma comment( lib, "opencv_core2410d.lib" )
#pragma comment( lib, "opencv_features2d2410d.lib" )
#pragma comment( lib, "opencv_flann2410d.lib" )
#pragma comment( lib, "opencv_gpu2410d.lib" )
#pragma comment( lib, "opencv_highgui2410d.lib" )
#pragma comment( lib, "opencv_imgproc2410d.lib" )
#pragma comment( lib, "opencv_legacy2410d.lib" )
#pragma comment( lib, "opencv_ml2410d.lib" )
#pragma comment( lib, "opencv_nonfree2410d.lib" )
#pragma comment( lib, "opencv_objdetect2410d.lib" )
#pragma comment( lib, "opencv_ocl2410d.lib" )
#pragma comment( lib, "opencv_photo2410d.lib" )
#pragma comment( lib, "opencv_stitching2410d.lib" )
#pragma comment( lib, "opencv_superres2410d.lib" )
#pragma comment( lib, "opencv_ts2410d.lib" )
#pragma comment( lib, "opencv_video2410d.lib" )
#pragma comment( lib, "opencv_videostab2410d.lib" )
#else
#pragma comment( lib, "IlmImf.lib")
#pragma comment( lib, "libjasper.lib")
#pragma comment( lib, "libjpeg.lib")
#pragma comment( lib, "libpng.lib")
#pragma comment( lib, "libtiff.lib")
#pragma comment( lib, "zlib.lib")
#pragma comment( lib, "opencv_calib3d2410.lib" )
#pragma comment( lib, "opencv_contrib2410.lib" )
#pragma comment( lib, "opencv_core2410.lib" )
#pragma comment( lib, "opencv_features2d2410.lib" )
#pragma comment( lib, "opencv_flann2410.lib" )
#pragma comment( lib, "opencv_gpu2410.lib" )
#pragma comment( lib, "opencv_highgui2410.lib" )
#pragma comment( lib, "opencv_imgproc2410.lib" )
#pragma comment( lib, "opencv_legacy2410.lib" )
#pragma comment( lib, "opencv_ml2410.lib" )
#pragma comment( lib, "opencv_nonfree2410.lib" )
#pragma comment( lib, "opencv_objdetect2410.lib" )
#pragma comment( lib, "opencv_ocl2410.lib" )
#pragma comment( lib, "opencv_photo2410.lib" )
#pragma comment( lib, "opencv_stitching2410.lib" )
#pragma comment( lib, "opencv_superres2410.lib" )
#pragma comment( lib, "opencv_ts2410.lib" )
#pragma comment( lib, "opencv_video2410.lib" )
#pragma comment( lib, "opencv_videostab2410.lib" )
#endif
#pragma comment( lib, "User32.lib")
#pragma comment( lib, "gdi32.lib")
#pragma comment( lib, "vfw32.lib" )
#pragma comment( lib, "comctl32.lib" )
#pragma comment( lib, "AdvAPI32.lib" )
#pragma comment( lib, "ole32.lib" )
#pragma comment( lib, "advapi32.lib")
#pragma comment( lib, "oleaut32.lib")
大家按照上述步骤分别把Debug和Release都改成配套的,编译运行后,生成的.exe文件就可以在裸机上跑了~
以上是关于VS2013+opencv2.4.10静态链接方式创建方法的主要内容,如果未能解决你的问题,请参考以下文章
Win7 64 + VS2010 + OpenCV2.4.10环境配置