MATLAB Answers

0

Issue to export C++ simulink code - parameter output

Asked by Fabrice Jolivet on 8 Aug 2019
Latest activity Answered by Fabrice Jolivet on 18 Aug 2019
Hello,
I am experiencing difficulties to C++ export Simulink custom block code for a reuse in Qt application.
Currently export only generate "Real_t" parameters when I expect to have "double".
What do I need modify in Simulink to be able to generate C++ readable code.
Thanks in advance for your support,
Fabrice

  0 Comments

Sign in to comment.

Products


Release

R2019a

2 Answers

Answer by Fabrice Jolivet on 18 Aug 2019
 Accepted Answer

For the benefit of everyone, please find below Matlab team answer:
"First of all, I would like to make you aware of the proper way to replace the names used in code generation with custom names. In order to do so, you need to open the Configuration Parameters window, then navigate to the section "Code Generation>Data Type Replacement" and then check the box "Replace data type names in the generated code". Upon doing so, you will be able to insert a "Replacement Name" for each "Code Generation Name".
Unfortunately, you are not allowed to insert C keywords in those boxes. For instance, upon trying to insert "double" on the line corresponding to "real_T" (or any other line), the error "double is a C keyword and cannot be used as a replacement type" is shown. After consulting the development team, I have been made aware that there are multiple valid reasons why using C reserved keywords for Data Type Replacement is forbidden. Just as a matter of example, which I provide you informally, some reason is explained here.
Therefore, it looks like you have now two options to workaround this (outside of MATLAB):
  1. You can include the "rtwtypes.h" file (that we generate in the subfolder "slprj\ert\_sharedutils") in your compilation process (via your Qt project file).
  2. You can specify valid names for all your types in the Data Type Replacement pane (as I explained in the previous paragraph), and then "typedef" them in the C++ class (in Qt) that will make use of the generated code.
I would not exclude, as a third alternative option, that you can write a simple script that parses the whole generated source code and substitutes each of occurrence of "real_T" with "double" and the likes.
I hope that this hints can help you achieve what you want, since MATLAB does not offer the feature you described, for good reasons, as I wrote. Hence, I will now mark the case as closed with provided workaround."

  0 Comments

Sign in to comment.