Issue to export C++ simulink code - parameter output

조회 수: 1 (최근 30일)
Fabrice Jolivet
Fabrice Jolivet 2019년 8월 8일
답변: Fabrice Jolivet 2019년 8월 18일
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

채택된 답변

Fabrice Jolivet
Fabrice Jolivet 2019년 8월 18일
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."

추가 답변 (1개)

Archit Dhanani
Archit Dhanani 2019년 8월 12일

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by