MATLAB coder compiled C++ library error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj

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]
I think the configuration may need to be setup from MATLAB coder as well:
0ZY3h.png
And there is another configuration in vs 2017
29vhN.png
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

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.
Hi Mukund Sankaran,
In the specify option, do you aware of any ready web documentation on how to modify those setting to match with the setting in visual studio? At this point, i'm not too sure on how to proceed with the speficy option, for example, what is the correct syntax on modiyfing to other configuration?
Thank you and appreciate your feedback.
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.
Thanks, i will try again , appreciate the feedback

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products

Release

R2018b

Asked:

on 5 Dec 2018

Commented:

on 11 Dec 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!