vs2013+opencv静态编译遇到的问题和解决方法

首先设置工程属性:

1、C/C++ -->代码生成 -->运行库,debug模式选/MT,release模式选/MTD

2、链接器-->常规-->附加库目录,这里我填了两个目录一个是XXX(vs安装目录)\VC\lib和XXX(opencv安装目录)\\OpenCV\opencv\build\x86\vc12\staticlib

3、链接器-->输入-->附加依赖项,这里把staticlib目录下的有d的lib填上去

例如:IlmImfd.lib
libjasperd.lib
libjpegd.lib
libpngd.lib
libtiffd.lib
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_nonfree249d.lib
opencv_objdetect249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_videostab249d.lib
zlibd.lib

接着编写一个简单的程序,参考了网上一些文章说在程序中加入以下的库

#pragma comment( lib, "comctl32.lib" )
#pragma comment( lib, "vfw32.lib" ) 

但编译后还是出现很多error。。。如下:

opencv_highgui249d.lib(window_w32.obj) : error LNK2019: 无法解析的外部符号 __imp__BitBlt@36,该符号在函数 "long __stdcall HighGUIProc(struct HWND__ *,unsigned int,unsigned int,long)" (?HighGUIProc@@YGJPAUHWND__@@IIJ@Z) 中被引用
1>opencv_highgui249d.lib(window_w32.obj) : error LNK2019: 无法解析的外部符号 __imp__CombineRgn@16,该符号在函数 "long __stdcall MainWindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?MainWindowProc@@YGJPAUHWND__@@IIJ@Z) 中被引用
1>opencv_highgui249d.lib(window_w32.obj) : error LNK2019: 无法解析的外部符号 __imp__CreateCompatibleDC@4,该符号在函数 _cvNamedWindow 中被引用
1>opencv_highgui249d.lib(window_w32.obj) : error LNK2019: 无法解析的外部符号 __imp__CreateRectRgn@16,该符号在函数 "long __stdcall MainWindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?MainWindowProc@@YGJPAUHWND__@@IIJ@Z) 中被引用
1>opencv_highgui249d.lib(window_w32.obj) : error LNK2019: 无法解析的外部符号 __imp__DeleteDC@4,该符号在函数 "void __cdecl icvRemoveWindow(struct CvWindow *)" (?icvRemoveWindow@@YAXPAUCvWindow@@@Z) 中被引用
1>opencv_highgui249d.lib(window_w32.obj) : error LNK2019: 无法解析的外部符号 __imp__DeleteObject@4,该符号在函数 "long __stdcall MainWindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?MainWindowProc@@YGJPAUHWND__@@IIJ@Z) 中被引用
1>opencv_highgui249d.lib(window_w32.obj) : error LNK2019: 无法解析的外部符号 __imp__FillRgn@12,该符号在函数 "long __stdcall MainWindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?MainWindowProc@@YGJPAUHWND__@@IIJ@Z) 中被引用
1>opencv_highgui249d.lib(window_w32.obj) : error LNK2019: 无法解析的外部符号 __imp__GetCurrentObject@8,该符号在函数 "bool __cdecl icvGetBitmapData(struct CvWindow *,struct tagSIZE *,int *,void * *)" (?icvGetBitmapData@@YA_NPAUCvWindow@@PAUtagSIZE@@PAHPAPAX@Z) 中被引用
1>opencv_highgui249d.lib(window_w32.obj) : error LNK2019: 无法解析的外部符号 __imp__GetStockObject@4,该符号在函数 _cvInitSystem 中被引用

。。。。。。。

查了下说是库没有添加完全,但我已经把staticlib中的所有lib添加进去还是不行,而comctl32.lib这种lib又不太懂,纠结大半天后偶然找到了缺少的lib

完整程序如下:

#include
#include
#include

using namespace std;
using namespace cv;
#pragma comment( lib, "comctl32.lib" )
#pragma comment( lib, "vfw32.lib" ) 
#pragma comment(lib,"User32.lib")
#pragma comment(lib,"Gdi32.lib")
#pragma comment(lib,"winmm.lib")
#pragma comment(lib,"uuid.lib")
#pragma comment(lib,"winspool.lib")
#pragma comment(lib,"wsock32.lib")
#pragma comment(lib,"rpcrt4.lib")
#pragma comment(lib,"odbc32.lib")
#pragma comment(lib,"oleaut32.lib")
#pragma comment(lib,"advapi32.lib")
#pragma comment(lib,"comdlg32.lib")
#pragma comment(lib,"ole32.lib")

int main()
{
Mat img = imread("C:\\Users\\manu\\Desktop\\image.jpg");
imshow("image", img);
waitKey();
return 0;
}

程序中有些lib(例如ole32.lib)删掉对这个简单的程序没有影响,但如果用到一些其他的opencv函数可能就需要这个lib,也有可能需要另外的lib。

你可能感兴趣的:(opencv)