Main Content

Resolve Incompatible Debug Build for C++ Library on Windows

Issue

If your MATLAB® interface includes a C++ shared library file built in debug mode, it might be incompatible with MATLAB, causing your program to terminate. When the library passes data to MATLAB or takes ownership of data created by MATLAB, MATLAB and the library must use the same C or C++ run-time library. Microsoft® provides debug versions of the run-time libraries that are not compatible with the release version of the run-time libraries that MATLAB uses. However, you can change a debug project configuration to use a compatible version of a library.

Possible Solution

Configure your debug project using the same (nondebug) C/C++ run-time library as MATLAB.

For example, in Microsoft Visual Studio® 2022:

  1. Highlight your project in the Solution Explorer, and then select Project > Properties.

  2. Under Configuration Properties > C/C++ > Preprocessor, remove _DEBUG from Preprocessor Definitions.

  3. Under Configuration Properties > C/C++ > Code Generation, change Runtime Library to Multi-threaded DLL (/MD).

After you build this project, add the dynamic-link library (.dll) file to your library configuration as a compiled library file.

See Also

Topics