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

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.

Related

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.

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

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.

Unknown external symbol _WinMainCRTStartup

I've been trying to solve this linker error for the last 3 hours, I keep getting errors saying that I have unresolved external symbol of _WinMainCRTStartup. Does anyone know what could be causing this error? I am using SDL's main function definition (SDL_main)
I also tried recreating the project incase something was accidentally changed, but the error persists.
The full output is here
https://gist.github.com/Joshhua5/73fe4235724d95e53f48
You're getting lots of unresolved external symbols, not just _WinMainCRTStartup. This usually indicates you're not linking a library you need to, and given the names of the functions it looks like it's the C runtime library (controlled with the /MTd etc. flags, or "C/C++ -> Code Generation -> Runtime Library" in the project properties dialogue.
I think I see the problem though; this line near the bottom:
4>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\OLDNAMES.lib : warning LNK4272: library machine type 'UNKNOWN' conflicts with target machine type 'X86'
... suggests you're using the VS2015 preview, and I don't imagine there's a release of SDL for that toolset yet, so I guess you're linking old libraries (which expect to be linked with an older toolset). Is that right? If so, you'll need to build SDL yourself.
Another possibility is simply that you've got the wrong subsystem type set - SDL will be expecting either /SUBSYSTEM:CONSOLE or /SUBSYSTEM:WINDOWS (set in "Linker -> System -> SubSystem"). Try choosing whichever one isn't chosen now.

Getting [fatal error C1007: unrecognized flag '-archVFPv3-D32' in 'p2'] error while compiling win8 app

Sometimes I getting this error:
fatal error C1007: unrecognized flag '-archVFPv3-D32' in 'p2'
Visual Studio 2013, Windows Store app (c++ and c# projects).
It seems that full rebuild resolve this problem - until next time.
Any ideas?
Thanks
This can also occur when you have changed the compiler and the static libs that you are linking to are compiled using a different compiler. E.g. different versions of MSVC compilers.
I got this problem too. And my mistake was:
1) Using .lib file which compiled how a Debug and i use him in Release mode app
In general, my app was get old .lib with old parameters from error link.
I updated parameter in Configuration Properties -> Linker -> General -> Additional Library Directories and all works at fine.

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.