Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine Debug with Release for C++ .lib in Visual Studio

I'm trying to make my C++ into a .lib file to use with my projects.

I have the files Log.h and Log.cpp.

I went into my project properties in Visual Studio and changed the configuration type from .exe to .lib. I set the build mode to Release and built my class into a file called Log.lib.

In a new C++ project, I'm trying to include that .lib file I made along with the Log.h file. All was successful, it recognised my functions, but when I try to run my exe program with my included Log.h, I get the following errors:

mismatch detected for '_ITERATOR_DEBUG_LEVEL':
    value '2' doesn't match value '0' in main.obj

By referencing this stackoverflow post, I discovered that building and running my new project in Release mode (the same as the .lib mode) removes the errors and I can successfully run my program and use the Log.h.

How can I compile my Log.h lib to be compatible with both Debug and Release?

like image 989
Ari Seyhun Avatar asked Dec 03 '25 23:12

Ari Seyhun


1 Answers

You have a mismatch in the version of the C runtime library that your projects are linking to. One of the projects is linking to the debug version of the CRT, while the other one is linking to the release version of the CRT. That mixed configuration is not supported, and it is resulting in the error message. The standard library template classes are actually different in debug and release builds.

You need to check the settings for all of your projects (everything that generates either an EXE or a LIB file as output), and ensure that they are all using the same version of the CRT. This is the /MT or /MD switches passed to the compiler.

like image 168
Cody Gray Avatar answered Dec 05 '25 12:12

Cody Gray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!