opencv staticLibrary

http://blog.csdn.net/yuanzhijing/article/details/51725531

用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
注意中间用(英文的分号);隔开

opencv staticLibrary_第1张图片

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属性页)

opencv staticLibrary_第2张图片

C/C++—代码生成—运行库:静态debug-/MTd ,静态release-/MT

opencv staticLibrary_第3张图片

连接器-输入-附加依赖项:
这里有两种方法,
一是附加依赖项添加opencv静态库文件:

opencv staticLibrary_第4张图片

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

二是,附加依赖项不添加:

opencv staticLibrary_第5张图片

但是要建立个头文件(或者直接在主函数里),加入以下命令:

#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")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63

大家按照上述步骤分别把Debug和Release都改成配套的,编译运行后,生成的.exe文件就可以在裸机上跑了~


你可能感兴趣的:(opencv staticLibrary)