Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using static libraries instead of dynamic libraries in opencv

Tags:

I have a project in visual studio 2012 which uses opencv dynamic libraries. It compiled, linked and worked well.

I want to change the project so it uses static libraries instead of dynamic libraries.

I changed the library directories in project VC++ directory from

  C:\thirdparty\opencv\build\x86\vc11\lib 

to: C:\thirdparty\opencv\build\x86\vc11\staticlib

but when I want to build the project, I am getting a lot of linker error such as:

 Error  110 error LNK2001: unresolved external symbol _TIFFWriteScanline    myproject\opencv_highgui245.lib(grfmt_tiff.obj)  

and more importantly a lot of error such as this:

 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)     

What other changes should I do to convert a project which uses dynamic libraries to use static libraries?

Edit 1

After change /md to /mt and adding some new libraries to the list of input libraries:

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 

I am getting some new errors:

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)     

Apparently some library is missing, but which one?

Edit 2 need to add more library to list. Full list of library is as follow:

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 

This solved the problem.

like image 755
mans Avatar asked May 30 '13 07:05

mans


2 Answers

I am able to get the static libraries working in VS 2013 by changing the project's Runtime Library to /MTd

enter image description here

and then including these Linker >> Input >> Additional Dependencies:

opencv_core248d.lib opencv_imgproc248d.lib opencv_highgui248d.lib opencv_ml248d.lib opencv_video248d.lib opencv_features2d248d.lib opencv_calib3d248d.lib opencv_objdetect248d.lib opencv_contrib248d.lib opencv_legacy248d.lib opencv_flann248d.lib libpngd.lib libtiffd.lib zlibd.lib IlmImfd.lib libjasperd.lib libjpegd.lib comctl32.lib gdi32.lib vfw32.lib 
like image 158
Jason Kleban Avatar answered Sep 30 '22 19:09

Jason Kleban


If you are building using CMake then it is very simple because it is one of the OpenCV CMake options; just set BUILD_WITH_STATIC_CRT to off. Eg. on the CMake command-line

-DBUILD_WITH_STATIC_CRT=OFF 
like image 21
G Huxley Avatar answered Sep 30 '22 19:09

G Huxley