Using a static library when creating a DLL in visual studio

I am trying to create a DLL using the Visual Studio 12 community, which depends on OpenCV.

I want to include OpenCV in .lib files, so I do not need to distribute it separately, but I need my file to be created as a DLL.

But I can not configure Visual Studio to import lib into a DLL. If in

My project → Properties → Configuration Properties → General → Configuration Type,

I select "static library (.lib)" and in:

My project → Properties → Configuration Properties → VC ++ Directories → Library Directories,

I choose the path to the OpenCV.lib files and

My project -> Properties -> Configuration Properties -> Connector -> Dependencies

I add a link to every .lib, it works.

But if I changed the configuration type, make a "dynamic library (DLL)", Visual studio tells me:

opencv_highgui2410d.lib(window.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in VectorsImport.obj 

It seems I can only do .lib files with .lib files. But that seems unlikely. I looked through this, but I only find manuals on how to create .lib or .dll files, or one from the other. It should be pretty simple, but I can't figure it out. I'm used to Linux where .o can be easily included in .so. It puzzles me.

+5
source share
1 answer

The error indicates that you are trying to link an OpenCV module that was compiled to use a static C / C ++ runtime with debugging support using the VectorsImport.obj module (possibly from your own project) that was compiled to use dynamic C / C ++ runtime with debugging support. Four variants of the C runtime library are not compatible in the Microsoft SDK, so all object files (either from your project or from statically linked libraries) must match this parameter. In Visual Studio 2010, it can be found in C / C ++ - Compiler -> Codegeneration -> Runtime library.

Please note that (as underlined in bold) it is not that OpenCV is a DLL or .lib, but if OpenCV is linked as a separate DLL, it is allowed to use a different type of C runtime library, so the mismatch does not matter.

+2
source

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


All Articles