Main Content

Troubleshoot C++ Standard Template Library (STL) Compilation Errors for Real-Time Application

To include a C++ project, I wrap the source into an S-Function block that is compatible with the金宝app®Desktop Real-Time™code generation target,sldrt.tlc. The C++ project uses the C++11 Standard Template Library (STL) interfaces, such asstd::vector,std::stack, andstd::complex. I can successfully compile the project inConnected IOmode. But, when I compile inRun in Kernelmode, I get compilation errors such as:

 file not found  file not found

这个问题是什么意思

The compiler generates these errors because the C++ standard template library is not compatible with real-time code.

In real-time code, there is a requirement to always finish a single time step on time, before the next one is due to start. This requirement produces time-deterministic behavior for the real-time code and produces more or less fixed execution time.

By comparison, the C++ standard template library frequently uses features that are not time-deterministic. The most notable examples are dynamic memory allocation and exceptions. While dynamic memory allocation is (with some limitations) supported by the real-time kernel in a real-time deterministic way, exceptions are not. So, it is not possible to use code that can throw exceptions.

This issue causes most of the STL headers to be unavailable with theSimulink Desktop Real-Timecode generation target. These interfaces throw exceptions. You cannot run code that uses the STL in the real-time kernel.

Try This Workaround

To eliminate the compiler errors, modify your project not to use the C++ standard template library.

If you are not able to modify your project not to use the C++ standard template library, you can use theSimulink Desktop Real-Timecode generation target inConnected IOmode.

ForConnected IOmode, compile the S-function as you would for Simulink. Then, run the model. The real-time requirements cannot be enforced, but the real-time misses are reported as they occur.