Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a static library when building a DLL in visual studio

I'm trying to build a DLL using Visual Studio 12 Community that depends on OpenCV.

I want to include OpenCV as .lib files so I don't have to distribute it seperately, but I need my file to be built as a DLL.

But I can't configure Visual Studio to import a 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 select the path to the OpenCV .lib files, and in

My Project -> Properties -> Configuration Properties -> Linker -> Addition Dependencies

I add a reference to each .lib, it works.

But if I change the Configuration Type do "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 make .lib files with .lib files. But that seems very unlikely. I've looked this up, but I only find guides on how to make .lib files or .dll files or one out of the other. This must be pretty simple, but I can't figure it out. I'm used to Linux, where a .o can pretty easily be included into a .so . This puzzles me.

like image 302
eje211 Avatar asked Dec 23 '14 18:12

eje211


1 Answers

The error indicates that you are trying to link a OpenCV module which has been compiled for using the static C/C++ runtime with debugging support with a module VectorsImport.obj (probably from your own project), which has been compiled for using the dynamic C/C++ runtime with debugging support. The 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 libs) have to match on that setting. On Visual Studio 2010, it could be found at C/C++-Compiler -> Codegeneration -> Runtime library.

Please note that (as the bold face should emphasize) it is not about OpenCV being a DLL or .lib, but in case OpenCV is linked as separate DLL, it is allowed to use a different kind of C runtime library, so the mismatch does not matter.

like image 95
Michael Karcher Avatar answered Sep 22 '22 16:09

Michael Karcher