LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in file.obj - c++

I am Integrating Matlab, C and Cuda together in a project. I used Matlab mix in order to connect matlab mx function written in c with the cuda runtime library, a linking error appear about conflict in static release and dynamic release between the c file and the library. Can anyone solve this?
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in file.obj.

This error can occur when you are statically linking your project with a library (typically a file with .lib extension) but the linker setting in your Visual Studio project are set to dynamically link (meaning the link will occur during runtime, usually with a .dll file).
To define that you need the project to use static linking start Visual Studio. In the Solution Explorer pane, right click the project name, and select Properties. Expand the properties as shown in the figure below: C/C++ --> Code Generation --> Runtime Library, select the Multi-threaded (/MT) option from the dropdown menu.

The library and your project must be linked with the same settings with regards to the C Runtime Library.
In your case one was linked against the CRT DLL (/MD) and the other was linked statically (/MT).
You just need to make sure both match and this error will go away.

for sharing purpose.
I'm using 2017 VS version which successfully open and run an old 2008 solution. Now, if for some reason, even if you change all your libraries and your main project to have the same runtime library param (under properties, see above posters) but you are still getting the same error message, try opening each individual .vcxproj file. Search under "RuntimeLibrary" and make their value same throughout all the vcxproj files. For some reason, these vcxproj files never update to the same value that I stated in the properties settings and I have to change them manually in the vcxproj.
Optionally, if you wish, open vcproj files too and change their "RuntimeLibrary" to be the same as well. Here the value is in digit.

Here are proper steps to fix
Error 69 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease'
this mean that runtime lib is static aka lib ( MT_StaticRelease ) Which is different then you project value Dynamic Lib aka dll (MD_DynamicRelease)
right click on solution
click properties
configuration properties -> General
change Configuration Type to Static Lib (lib) from Dynamic Lib (dll)
In case you have reverse scenario and the above steps not fix problem then play with this option
C/C++ --> Code Generation --> Runtime Library select Multi threaded

As others have mentioned the runtime library switch on cl.exe must match between all of the compiled modules. In MSBuild this is referenced as ClCompile>/RuntimeLibrary.
However, even if these match you might still encounter this problem if there is a "#undef DEBUG" or "#undef _DEBUG" somewhere in your project. The yvals.h header that is part of the VC++ runtime library headers can change what is compiled into your obj files if these macros are changed.
Use "dumpbin /all foo.obj >foo.txt" to check what is actually going into your obj files. Look for the header "Linker Directives" in that output.

This would work better as a comment to GWKit but I don't have the reputation for it. He mentions having to update the vcxproj files because they don't actually change. In my case they only saved after hitting "saveAll" and then closing visual studio. I got a prompt asking if i want to save changes to properties which were saved and after clicking yes the vcxproj files were properly updated.

This linker error occurred due to the improper project configuration, may be you have built the library in a configuration which is different from the main project configuration . If your project configuration is release\debug, then you should choose the same configuration while building your library.

Related

what is libcpmtd.lib for?

All of a sudden, my program got link errors like below:
libcpmtd.lib(xlock.obj) : error LNK2038: 'RuntimeLibrary' unmatched.The value 'MTd_StaticDebug' is different from that of [project x], which is: 'MDd_DynamicDebug'
Since this error suddenly appeared on multiple computers, I believe this was not caused by unintended modification of any file.
Version: Visual Studio 2013
Question-1:
Could you give any hint about the reason of this error and how to solve it?
What I did:
I remove the libcpmtd.lib from the import library list of project setting, then the build error disappeared and everything was OK.
But, I am not sure what libcpmtd.lib is for?
Google told me there is CRT inside, but what are the content specifically?
Perhaps this library was added and then not relevant from some point of time.
Question-2:
what is in side libcpmtd.lib? I want to figure out what I might have lost after I removed the lib.
These are the C++ standard runtime libraries. With Visual C++, you have 2 options, which give you 4 permutations of the library it links to.
Debug v.s. Release
As it suggests, do you want the C++ runtime lib that has additional error checking?
Static v.s. Dynamic
If you happen to be compiling only a simple exe, then linking to the library statically should be fine. If however you have a large project consisting of multiple DLL's, then it makes sense to load the CRT dynamically (so it can be shared between the DLL's, rather than being duplicated into each one).
So what you have is a mis-configured build. You'll need to check the C/C++ Runtime Library settings for each library, DLL, and exe within your project (which you can find in your project settings, under C/C++ -> Code Generation).
You will need to make sure that each one links to the same runtime library (i.e. Debug DLL for all debug settings, Release DLL for all release settings).
If that doesn't fix it, then there are two other possible causes:
You have started linking to a 3rd party library, and that's the cause of the CRT mis-match. Most libs ship debug and release builds for this reason, so hopefully you'll just need to update the libs you are linking to.
You are inadvertently pulling in a Debug lib into a release build (or a release build lib, into a debug exe). For this you will need to check all of the additional library directories, and/or check to make sure all of the debug & release output directories are correct (i.e. you aren't accidentally compiling a debug lib into a release build folder).

Include static library in VS C++ project

Configuration I have
Windows 10 64bit
Visual Studio Community 2017 with Visual C++ 2017
CMake 3.9.0
opencv 3.3.0
Aim
Goal is to build opencv as a static library (.lib) and include into a Visual C++ project which is a DLL. Everything should be compiled for x86 architecture or simply 32bit.
Process
Latest opencv distributive does not contain dll's compiled for 32bit system and therefore, I need to compile own version. According to the opencv 2.4 documentation on "installation in Windows". I have compiled the library with BUILD_SHARED_LIBS option disabled and configured target project as described in "how to build applications with OpenCV inside the Microsoft Visual Studio".
Compilation of my project fails with following errors (totally error count is greater than 800)
Error type 1
LNK2038 mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug'
doesn't match value 'MDd_DynamicDebug' in main.obj
\opencv_core320d.lib(alloc.obj)
Error type 2
LNK2005 "public: void __thiscall std::basic_ostream<char,struct
std::char_traits<char> >::_Osfx(void)" (?_Osfx#?$basic_ostream#DU?
$char_traits#D#std###std##QAEXXZ) already defined in
opencv_core320d.lib(system.obj) \msvcprtd.lib(MSVCP140D.dll)
Error type 3
LNK2001 unresolved external symbol _ippicviHSVToRGB_16u_C3R#24
\opencv_imgproc320d.lib(color.obj)
I believe it may be due to uncoordinated compilation options or erroneous configuration of my project, but because I am heavy Linux user I experience difficulties with setting up these things on Windows.
Update
After I have matched configuration shown in the screen below block of errors about code generation mismatch disappeared, but undefined references are still there.
Thank you for help!
To resolve "Error type 3" add *.lib files from "staticlib" dir to "Linker->Input->Additional Dependencies". For example "_ipp" symbols are defined in "ipp_iw.lib" and "ippicvmt.lib".
Just for info. I successfully built opencv from sources as a static and shared library (as opencv_world3**.lib) using MSVS 2012 and cmake 3.9.0. But also done that with MSVS 2017 community.
PS. Maybe a TYPO but you said that you use opencv 3.3.0 but in error messages there is opencv_core320d.lib
PPS. "Error type 1" is the result of using static debug runtime version in opencv_core (MTd) and dynamic debug runtime in your app (MDd)
I always have the same problems. This is why I have a property sheet ready for use.
The steps to follow for static compilation are:
Remember to Build the INSTALL project in the CMake generated Solution. Let's call $(OPENCV_DIR) the folder where the install happened (usually something like xxx\install). You can create an environment variable for this.
Add in front of [Configuration Properties]->[VC++ Directories]->[Include Directories] $(OPENCV_DIR)\include;. The semicolon is to separate paths.
Add in front of [Configuration Properties]->[VC++ Directories]->[Library Directories] $(OPENCV_DIR)\x86\vc15\staticlib;.
Match the runtime library linkage mode between OpenCV and your project. If you unselect BUILD_SHARED_LIBS by default the CRT is statically linked (/MT for Release or /MTd for Debug). If you want it dynamically linked deselect BUILD_WITH_STATIC_CRT. So, as you already realized, fix it in [Configuration Properties]->[C/C++]->[Code Generation]->[Runtime Library].
Copy all filenames matching *.lib (*d.lib for Debug) and add them in [Configuration Properties]->[Linker]->[Input]->[Additional Dependencies] separated by semicolons.
It's quite painful, so do it once in a Property Sheet and just include it when needed.

Mismatch detected for 'RuntimeLibrary' for object files from source files from the same visual studio 2015 project

I have a common linker error in a situation where I do not understand why I get it. I changed a project from static linking (/MT) to dynamic linking (/MD). After this I get the following error:
Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't
match value 'MT_StaticRelease' in XY.obj XXX [some folders]\XYZ.obj
The source files for XY and XYZ are both part of the same project. The project is compiled with /MD. I first thought that some files have not been updated in my rebuild, so I cleaned the build and rebuild the project. Since I still got the same error, I manually deleted the build folder containing the .obj files and rebuild the project. I still get the error.
A second effect I don't understand is that an included library (which I changed from the static version to the dynamic version) does not find several symbols:
Error LNK2001 unresolved external symbol __imp__strncat LAAPTOF_Fuzzy_XOP
[some folders]\ccc_vc120_md.lib(MxNET.obj)
etc...
When I include the static version of the library, these errors disappear but I get no error with respect to a runtime library mismatch, which I expected to get.
All these errors only show up for the 32 bit version of the project. The 64 bit version builds fine. I've checked all parameters and they are the same except where a different one is required for the 64 bit version.
Can anybody explain to me what I might be doing wrong?
I've solved the problem. My project used to be a visual studio 2010 project. I've been warned that converting a project to a newer version of visual studio does not always run smooth, even if the converter tells you so. I don't know if this was really the problem, but after setting up a new project file, everything links correctly.

Visual Studio (C++) is automatically linking against an unwanted version of lib file

I am trying to create a C++ project in Visual Studio 2013 that has CGAL and Boost (and a couple of other libraries) as dependencies. I preferably like to link to these libraries dynamically. Also, I'd like to link to the "Release" versions of these libraries for performance reasons (not the "Debug" versions).
Starting from an empty C++ project, I added the path to header files of the aforementioned libraries as shown in the image below:
Inside the linker options, I then added the directories that contain the DLL and lib files of the external libraries. (CGAL directory contains CGAL's compiled DLL files along with lib files).
At this point, I have not added a single "lib" file "Additional Dependencies" dialog:
Now something weird is going on and I cannot explain why. If I try to build the project as-is (under the "Debug" configuration), I get a LNK1104 error about the linker not being able to find CGAL-vc120-mt-gd-4.7.lib. I know that the error means I should add the lib file in "Additional Dependencies" dialog...
But wait... WHAT...?!!
How does Visual Studio know how to automatically link against this lib file?! Worse yet, how does it know it needs the "debug" version of the library? (With the gd suffix). Also, how does it know I compiled CGAL with VS2013!!??
At first, I though the project was inheriting properties from some preset property sheets somewhere in my system. But I am certain that's not the case as this behavior shows even with a project created from scratch.
My main question is, how would you force Visual Studio to link against the "Release" version of this library? (eg. CGAL-vc120-mt-4.7.lib)
Side question but related: Am I even linking against the DLL files? How can I be certain that I am in deed doing dynamic linking and not static linking?
This is probably happening due to the #pragma comment(lib) mechanism - eg see What does "#pragma comment" mean?
This is a way of the compiler emitting instructions for the linker so that it can decide between multiple versions of a library depending on the compiler version. In this case it means that it can automatically pick up the correct version of the library (debug vs release, vs2013 vs vs2015, MT vs MD, etc). When you added the explicit reference to the library in Additional Dependencies then it is now trying to look for two files.
So, to fix the problem, remove it from Additional Dependencies and let VS pick the right library. If you are getting the LNK1104 error then it suggests that either the link library path isn't set up correctly, or you don't have the CGAL library file it's looking for. You can increase the verbosity settings for the linker in the Project Options to get more detail about what's happening.

error LNK2038: mismatch detected

There are lots of questions on this issue, but I'm struggling to get the answers to work for me. I have the specific error message:
gurobi_c++mdd2010.lib(Env.2010.omdd) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in DataHelper.obj
in visual studio 2010, in a release x64 build. The Gurobi library is 3rd party software, and DataHelper is my class.
Setting _ITERATOR_DEBUG_LEVEL=0 in DataHelper doesn't fix the problem, and I do not appear to be linking against 'debug' .lib or .dll in my files. _SECURE_SCL is not set in my files.
I tried to set _ITERATOR_DEBUG_LEVEL=2 in the preprocessor definitions, and I get:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\yvals.h(113): fatal error C1189: #error : _ITERATOR_DEBUG_LEVEL > 1 is not supported in release mode.
Can anyone confirm the problem is on my side, or on the 3rd party side, and suggest any workarounds if it is the 3rd party library?
Thanks
Melanie
If _ITERATOR_DEBUG_LEVEL > 1 is not supported in release mode and the error message implies that _ITERATOR_DEBUG_LEVEL == 2 in gurobi_c++mdd2010.lib, then either that lib or one of its dependencies must be a Debug build.
It's probably worth investigating this angle, so check here and make sure you are linking the correct lib, based on your project settings.
I had a similar problem with a solution that I migrated from VS2005 to VS2010. It had two projects, a static library and an executable. Apparently there are multiple ways to instruct VS2010 to link a static library into an executable. One of those methods is via "Framework and References" on Property Pages for the executable's project. Click on "Add New Reference..." and add the static library here and it will give the linker error described in the OP's question because it doesn't care about debug vs release builds - it will grab the same static library for both, which results in an error for one of the two. My solution was to remove the reference (click "Remove Reference"), and then use the "Linker > Input > Additional Dependencies" and "Linker > General > Additional Library Directories".
You need to link gurobi_c++md2010.lib instead of gurobi_c++mdd2010.lib.
The second d in mdd stands for debug.