Generating reentrant code with C++ classes from MATLAB® code increases the chances of stack overflow during code execution. Code generation might stop and produce this message:
Code generator failed to produce C++ destructor for MATLAB class 'y'.
Generated code is not exception-safe. To enable generation of C++ destructor,
disable 'Generate Re-entrant code (MultiInstanceCode)' configuration
This message might appear if both these conditions are true:
You choose to generate C++ code with classes from MATLAB code by setting
true in the configuration object (
or in the project build settings, by setting
the Generate C++ classes from MATLAB classes check box.
You choose to generate reentrant code by enabling the
MultiInstanceCode parameter in a code
configuration object, or by enabling the Generate re-entrant
code parameter in the Memory tab of
The destructor of a class in your MATLAB code has a persistent variable or calls another function that declares and uses a persistent variable.
Depending on whether the type of code you want to generate, try one of these solutions.
You can raise the stack limit to generate reentrant code that has C++ classes for MATLAB classes. Do one of the following:
Raise the stack limit by doubling the stack value until code generation succeeds. The code generator then might have sufficient memory to generate C++ classes in reentrant code.
The maximum configurable stack limit depends on the linker in your system. The default stack size varies based on your operating system and system configuration.
The destructor of a class in your MATLAB code must not have a persistent variable or call another function that declares a persistent variable.
To generate code that contains C++ classes for MATLAB classes, you can disable generation of reentrant code. Do one of the following:
In the code configuration object, disable the
In the MATLAB Coder app, disable the Generate re-entrant code parameter.
You can change the default behavior of the code generator to produce structures for MATLAB classes. Do one of the following:
In the MATLAB
Coder app, set Language to
C++. In the project build settings, clear the
Generate C++ classes from MATLAB classes check box.