Debug-mode compilation in Windows uses release-mode C and C++ standard libraries
1 view (last 30 days)
Show older comments
When I compile a mex with the -g (debug mode) option in Windows, Visual Studio is passed the flag /MD (at least in Matlab 2013b/2015a), which selects the release-mode C and C++ standard libraries.
When building in debug-mode outside of Matlab, the default (e.g. in CMake) is to use /MDd and /D_DEBUG, which selects the debug-mode C and C++ standard libraries. When such a library is linked to in Matlab, Visual Studio emits the LNK4098 conflicting library warning.
The warning — which should be fixed — can be fixed by changing either Matlab's build flags, or the library's build flags.
Why doesn't Matlab use /MDd in debug-mode, to select the debug-mode standard libraries?
0 Comments
Answers (1)
Philip Borghesani
on 4 Jun 2015
Mex files have always been built and linked against release versions of the libraries to avoid conflicts caused by mixing release and debug versions of the libraries. To safely use the debug libraries all components that transfer ownership of objects or pass c++ objects must be linked with the same library. Supporting debug libraries could require shipping many components of Matlab and third party components with debug and release builds.
0 Comments
See Also
Categories
Find more on Call C++ from MATLAB 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!