0

In my debug built i did not really care if my libraries get statically linked or not. Though now for my release built i'd like to statically link some things. Thus i changed from /MDd to /MT for my release build.

error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj

This is the error i am receiving.

Do i need to set anything else to statically link libraries? It is also telling me in a warning that it is linking MSVCRTD. Shouldn't it link MSVCRT in a release build?

kek5chen
  • 96
  • 10
  • You need to switch from `/MDd` to `/MTd` the `d` at the end means you are using a Debug build. The error is because you are trying to mix debug and release. Thankfully your compiler warns you of the undefined behavior. In Debug mode the standard library is implemented with extra parameters to track out of bounds and other error conditions. – drescherjm May 04 '22 at 16:55
  • But i am using a release build? I know the d means that its a debug build. But what is wrong with using MT? /MTd also does not work by the way. – kek5chen May 04 '22 at 16:57
  • Some part of your project has a Debug dependency that is pulling in the debug runtime. – drescherjm May 04 '22 at 16:57
  • 3
    Every library, project, source file needs to be compiled with the same `/MXy` setting including any 3rd party files. Make sure to do a `clean` and `full build`. – Richard Critten May 04 '22 at 16:58
  • I am only using standard windows header files. – kek5chen May 04 '22 at 16:58
  • @RichardCritten you wouldnt believe how many times i have tried this – kek5chen May 04 '22 at 17:00
  • Still, it's low-hanging fruit that people trip over all the time, so it's worth mentioning. – user4581301 May 04 '22 at 17:03
  • You probably have to edit your question and add the exact text of the compiler command line from the `c/c++ ->Command Line-> All options box` for the Release configuration – drescherjm May 04 '22 at 17:05
  • Alright. I have found something out. I am compiling to .exe, if i want to compile a static .lib file it works. But i need a statically linked .exe file... I think my general approach was wrong? – kek5chen May 04 '22 at 17:07
  • ***I think my general approach was wrong?*** No, I think you made some type of typo. – drescherjm May 04 '22 at 17:10
  • So the libraries it is trying to link are compiled with /MDd. I think i have to recompile the dependencies which are default c++ libraries using /MT. But how would i go about that? https://stackoverflow.com/questions/37398/how-do-i-make-a-fully-statically-linked-exe-with-visual-studio-express-2005 has kind of my approach – kek5chen May 04 '22 at 17:13
  • ***But how would i go about that?*** Depends completely on the libraries used and how you are compiling them. For me a lot of projects use CMake and that normally generates Debug and Release binaries when using msvc. – drescherjm May 04 '22 at 17:15
  • i am using the header files: Windows.h, thread, TlHelp32.h. All default windows libs. – kek5chen May 04 '22 at 17:17
  • If all of the code is in your own solution, make all your Release projects use the same runtime. Make all your Debug configurations use the same runtime. Make sure that you link to your Debug libraries in Debug mode and your Release libraries in Release mode. – drescherjm May 04 '22 at 17:18
  • There is only one project – kek5chen May 04 '22 at 17:19
  • Then please edit your question and add the text from the `c/c++ ->Command Line-> All options box` properties page for your project in Release mode. Remember that the Debug settings and Release settings are independent. – drescherjm May 04 '22 at 17:20
  • There is no options in there – kek5chen May 04 '22 at 17:27
  • Here is what that dialog looks like for me in Visual Studio 2019: [https://pasteboard.co/keITm18jbZWp.png](https://pasteboard.co/keITm18jbZWp.png) – drescherjm May 04 '22 at 17:31
  • I have been trying to find out which header file had a dependency which hadnt been compiled statically. I found out this was ``. I replaced it with windows.h's CreateThread function and the executable was compiled and linked successfully. I am guessing that ucrtbase.dll (which relies on) only comes as ucrtbased.dll in the debug version which is not linkable using /MT. – kek5chen May 04 '22 at 17:34
  • But what if i wanted to link ucrtbase.dll statically? – kek5chen May 04 '22 at 17:35
  • The documentation says link to `libucrt.lib` here: [https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170](https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170) – drescherjm May 04 '22 at 17:47
  • ah, i didnt find that resource. thanks for sharing. makes sense that i cant statically link to dll files and instead have to use libs. didnt think of that. – kek5chen May 05 '22 at 16:36

0 Answers0