我在 Visual Studio 2012 中有一个使用 opencv 动态库的项目。它编译,链接并且运行良好。
我想更改项目,使其使用静态库而不是动态库。
我将项目 VC++ 目录中的库目录从
C:\thirdparty\opencv\build\x86\vc11\lib
到:C:\thirdparty\opencv\build\x86\vc11\staticlib
但是当我想构建项目时,我收到很多链接器错误,例如:
Error 110 error LNK2001: unresolved external symbol _TIFFWriteScanline myproject\opencv_highgui245.lib(grfmt_tiff.obj)
更重要的是很多错误,例如:
Error 1 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in myproject.obj myproject\opencv_core245.lib(system.obj)
我应该做哪些其他更改才能将使用动态库的项目转换为使用静态库?
编辑 1
将 /md 更改为 /mt 并将一些新库添加到输入库列表后:
opencv_calib3d245.lib
opencv_contrib245.lib
opencv_core245.lib
opencv_features2d245.lib
opencv_flann245.lib
libtiff.lib
libpng.lib
libjpeg.lib
libjasper.lib
IlmImf.lib
zlib.lib
opencv_gpu245.lib
opencv_haartraining_engine.lib
opencv_highgui245.lib
opencv_imgproc245.lib
opencv_legacy245.lib
opencv_ml245.lib
opencv_nonfree245.lib
opencv_objdetect245.lib
opencv_photo245.lib
opencv_stitching245.lib
opencv_ts245.lib
opencv_video245.lib
opencv_videostab245.lib
我收到一些新错误:
Error 9 error LNK2001: unresolved external symbol _AVIFileCreateStreamA@12 myproject\opencv_highgui245.lib(cap_vfw.obj)
Error 8 error LNK2001: unresolved external symbol _AVIFileGetStream@16 myproject\opencv_highgui245.lib(cap_vfw.obj)
Error 5 error LNK2001: unresolved external symbol _AVIFileInit@0 myproject\opencv_highgui245.lib(cap_vfw.obj)
Error 7 error LNK2001: unresolved external symbol _AVIFileOpenA@16 myproject\opencv_highgui245.lib(cap_vfw.obj)
显然有些图书馆不见了,但哪一个?
编辑 2 需要将更多库添加到列表中。完整的库列表如下:
opencv_calib3d245.lib
opencv_contrib245.lib
opencv_core245.lib
opencv_features2d245.lib
opencv_flann245.lib
libtiff.lib
libpng.lib
libjpeg.lib
libjasper.lib
IlmImf.lib
zlib.lib
opencv_gpu245.lib
opencv_haartraining_engine.lib
opencv_highgui245.lib
opencv_imgproc245.lib
opencv_legacy245.lib
opencv_ml245.lib
opencv_nonfree245.lib
opencv_objdetect245.lib
opencv_photo245.lib
opencv_stitching245.lib
opencv_ts245.lib
opencv_video245.lib
opencv_videostab245.lib
Vfw32.Lib
comctl32.lib
这解决了问题。