using static libraries instead of dynamic libraries in opencv

后端 未结 5 1067
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 08:31

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 libra

5条回答
  •  情话喂你
    2020-12-01 08:41

    For Visual Studio 2012 with OpenCV 3.0.0, these problems still apply, and the solutions in this thread are relevant. Here's my setup to get it to work:

    Windows' System Environment Variables

    Set in Windows' System Environment Variables: OPENCV_DIR = D:\OpenCV\build\x64\v11 (replace D:\OpenCV\ with whatever your path to opencv is. Also, x64 for 64-bit machines, x86 for 32-bit machines).

    Use staticlib for AdditionalLibraryDirectories

    Set the Additional Library Directories (View > Property Pages > Configuration Properties > Linker > General > Additional Library Directories) to: $(OPENCV_DIR)\staticlib;%(AdditionalLibraryDirectories)

    Runtime Library

    Change the Code Generation > Runtime Library to Multi-threaded Debug (/MTd) per uosɐſ's answer, otherwise you'll get this kind of error:

    Error   1   error LNK2038: mismatch detected for 'RuntimeLibrary': value
    'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in Source.obj
    C:\Users\...\documents\visual studio 2012\Projects\OpenCVTest2\OpenCVTest2\opencv_core300d.lib(alloc.obj)   OpenCVTest2
    

    Finally, the Additional Dependencies list

    My Additional Dependencies must include all the library names in the staticlib directory. Mind the version numbers; since I'm using OpenCV 3.0.0, the filenames ends with *300d.lib. I believe the comctl32.lib and vfw32.lib are not in the staticlib, but I added them just in case (View > Property Pages > Configuration Properties > Linker > Input > Additional Dependencies):

    opencv_calib3d300d.lib
    opencv_core300d.lib
    opencv_features2d300d.lib
    opencv_flann300d.lib
    opencv_hal300d.lib
    opencv_highgui300d.lib
    opencv_imgcodecs300d.lib
    opencv_imgproc300d.lib
    opencv_ml300d.lib
    opencv_objdetect300d.lib
    opencv_photo300d.lib
    opencv_shape300d.lib
    opencv_stitching300d.lib
    opencv_superres300d.lib
    opencv_ts300d.lib
    opencv_video300d.lib
    opencv_videostab300d.lib
    libtiffd.lib
    libpngd.lib
    libjpegd.lib
    libjasperd.lib
    IlmImfd.lib
    libwebpd.lib
    ippicvmt.lib
    zlibd.lib
    comctl32.lib
    vfw32.lib
    

    x86 vs x64

    I also ran into this issue that VS2012 claims the target machine does not match the module machine type like this guy. The solution is given here.

提交回复
热议问题