MATLAB coder compiled C++ library error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
Show older comments
Hi,
I tried to use a MATLAB coder compiled C++ library in vs 2017 but encountered the error below:
1> test_cv_2.lib(test_cv_2.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
1> test_cv_2.lib(test_cv_2.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in main.obj
1> LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library [1]
From my initial search in the web and i have look through this post: error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
I think the configuration may need to be setup from MATLAB coder as well:

And there is another configuration in vs 2017

Anyone have any idea on the correct settings based on the images above? Or is there any extra settings need to be done?
I have tried out several settings but the same error occur, for example, set Build configuration set to debug in MATLAB coder environment and Multi-threaded Debug DLL (/MDd) in vs 2017 setting.
Thank you.
4 Comments
Mukund Sankaran
on 5 Dec 2018
If you are using any precompiled code (*.obj, *.lib, *.dll), you'll need to make sure that the compiler/linker flags are identical in the toolchain options table. You can edit these settings by choosing the "Specify" option for Build Configuration in the MATLAB Coder settings page you've provided a screenshot for.
Also, here's an example on how to use a DLL generated from MATLAB Coder in Visual Studio - https://www.mathworks.com/help/coder/ug/use-a-c-dynamic-library-in-microsoft-visual-studio-project.html
Hope these suggestions are helpful.
kok wei
on 6 Dec 2018
Mukund Sankaran
on 6 Dec 2018
As far as I'm aware, there is no readily available documentation on how to modify those settings in the MATLAB Coder app. We will consider adding this information to the documentation.
You could start by looking at the compiler/linker flags in the "Command Line" section of the C/C++ configuration properties in Visual Studio, and map them to the ones used in MATLAB Coder. If you open the Makefile for your MATLAB Coder project (this resides under the codegen folder, and is typically named <project>_rtw.mk), you can see the values being used for the flags specified in the toolchain options table.
Alternatively, if you do not need precompiled code from MATLAB coder, you can generate code only by choosing "Source Code" as the build type in the Generate Code step. You can then compile all your code in Visual Studio, which would eliminate the need to tweak the toolchain options.
Hope this helps.
kok wei
on 11 Dec 2018
Answers (0)
Categories
Find more on MATLAB Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!