After C Code Generation Using Simulink/Embedded Coder, How to Use it in My C/C++ Project?

5 views (last 30 days)
If the result of C Code Generation fom Simulink/Embedded Coder contains such below function,
extern void Model_initialize(RT_MODEL_T *const Model_M)
{
....
}
extern void Model_step(RT_MODEL_T *const Model_M, real_T Model_U_arg1[3], real_T Model_U_arg2[6], real_T Model_U_arg3[9], real_T Model_Y_arg4[3])
{
....
}
extern void Model_terminate(RT_MODEL_T *const Model_M)
{
....
}
How to implement that code in my C/C++ Project?
I can do that with Matlab Coder and Matlab Function, but not with Simulink/Embedded Coder and Simulink Block Diagram.
I mean if I can make a Matlab Function, which works the same as the Simulink block diagram does, Matlab coder would give me such below function
extern void someFunction(const double arg1[3], const double arg2[6], const double arg3[9], const double arg4[3])
{
....
}
So I can just use that function, as including header and calling that function.
However, The reulst of Simulink/Embedded Coder seems to have different sturcture or mechanism with that of Matlab Coder. In my CMake Project, I got this error when call generated function
undefined reference to `Model_M_initialize(tag_RTM_Model_M_T*)'
undefined reference to 'Model_M_step(tag_RTM_Model_M_T*, double*, double*, double*, double*)'
Again, what to do to implement the C Code Function, Simulink/Embedded Coder gave me?

Accepted Answer

Benjamin Thompson
Benjamin Thompson on 16 Feb 2022
If you have ert.tlc selected as the System Target File in the Code Generation parameters, then go to Templates and make sure the option "Generate an example main program" is selected. Then Embedded Coder will create an ert_main.c or ert_main.cpp to show how to initialize and step the model.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!