调用OpenCV静态库

调用静态库的好处在于,发布软件时不需要附带dll,只需要一个.exe,但是文件的体积会比较大。


调用方法:


1、设置项目属性的目录,可执行目录:opencv\build\x86\vc11\bin,包含目录opencv\build\include,库目录opencv\build\x86\vc11\staticlib,注:vc11是VS21012,v12是VS2013……

2、脱离vs运行时库的办法:C/C++  -  代码生成 - 运行库 - 选择MT或MTd,分别对应release和debug,这样设置代表静态编译运行时库。如果设为MD,则会报错:缺少msvcp110.dll  

3、MFC中需要设置”在静态库中使用 MFC“


4、静态编译opencv库,添加附加依赖项有两种方法:

a. 链接器 - 输入 - 附加依赖项:

IlmImf.lib
libjasper.lib
libjpeg.lib
libpng.lib
libtiff.lib
opencv_calib3d249.lib
opencv_contrib249.lib
opencv_core249.lib
opencv_features2d249.lib
opencv_flann249.lib
opencv_gpu249.lib
opencv_highgui249.lib
opencv_imgproc249.lib
opencv_legacy249.lib
opencv_ml249.lib
opencv_nonfree249.lib
opencv_objdetect249.lib
opencv_ocl249.lib
opencv_photo249.lib
opencv_stitching249.lib
opencv_superres249.lib
opencv_ts249.lib
opencv_video249.lib
opencv_videostab249.lib
zlib.lib


(这是2.4.9版本的,Release下编译)


b. 代码中引用

#pragma comment( lib,"库名.lib" )

放在  头文件 引用的下面

你可能感兴趣的:(opencv)