Simulink embedded Matlab functions: Headerless coder.cinclude() for custom C/C++ functions

It’s well-known that you can use coder.ceval(...) in in conjunction with coder.cinclude(...) to run external C/C++ functions from embedded matlab functions:

What’s less known is that you an include C/C++ code “inline” in the coder.cinclude() call, albeit this is somewhat contrived. This is very helpful so you don’t have to manage header files.

Note that when compiling your model, Simulink/Matlab coder still needs to check if it compiles properly, so you need to ensure that “standalone” compilation of your code is possible.

Remember that it’s absolutely essential to use the dummy <math.h> include to terminate the #include line!

This will generate the following code in the header file:

and, with sufficient comment levels turned on, this is the code from the generated .cpp file


Check out similar posts by category: Matlab/Simulink