LNK2005 Error linking openCV static libraries with Visual Studio and QT Creator

I built openCV 2.3 static libraries. My project currently uses dynamic without problems, but now I want to use static libraries. I added the lib files to my .pro file:

LIBS += "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_calib3d231.lib" \ "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_contrib231.lib" \ "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_core231.lib" \ "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_features2d231.lib" \ "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_flann231.lib" \ "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_gpu231.lib" \ "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_haartraining_engine.lib" \ "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_highgui231.lib" \ "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_imgproc231.lib" \ "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_legacy231.lib" \ "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_ml231.lib" \ "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_objdetect231.lib" \ "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_ts231.lib" \ "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_video231.lib" 

And turn on the dirs:

 INCLUDEPATH += "C:\Program Files\openCV_VS_static\opencv\build\include" INCLUDEPATH += "C:\Program Files\openCV_VS_static\opencv\build\include\opencv" 

When I try to build, I get the following errors:

 LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRT.lib(MSVCR100.dll) LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRT.lib(MSVCR100.dll) LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRT.lib(MSVCR100.dll) LIBCMT.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in MSVCRT.lib(MSVCR100.dll) LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRT.lib(MSVCR100.dll) LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRT.lib(MSVCR100.dll) LIBCMT.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRT.lib(MSVCR100.dll) LIBCMT.lib(crt0dat.obj) : error LNK2005: __cexit already defined in MSVCRT.lib(MSVCR100.dll) LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRT.lib(MSVCR100.dll) LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" ( ?terminate@ @YAXXZ) already defined in MSVCRT.lib(MSVCR100.dll) LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRT.lib(cinitexe.obj) LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRT.lib(cinitexe.obj) LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRT.lib(cinitexe.obj) LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRT.lib(cinitexe.obj) LIBCMT.lib(errmode.obj) : error LNK2005: ___set_app_type already defined in MSVCRT.lib(MSVCR100.dll) LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library 

Any help or suggestions appreciated.

+6
source share
3 answers

In CMake, when creating openCV static libraries, in addition to unchecking the BUILD_SHARED_LIBS, I also unchecked the BUILD_WITH_STATIC_CRT flag and took care of this particular problem

+9
source

Make sure Project-> Configuration Properties-> c / C ++> Generation Code: Runtime Library is multi-threaded (/ MT)

+5
source

The problem is that your linker is trying to combine different incompatible versions of the Visual C ++ Runtime Library (CRT) into one separate file.
Let me guess in the wild: every part of your project and library you link to is NOT generated with the same code generation options in Visual C ++.
I wonder if the switch / NODEFAULTLIB'd switch to solve this call?

+1
source

Source: https://habr.com/ru/post/910678/


All Articles