Non-static function in generated code

조회 수: 24 (최근 30일)
Piotr Sawko
Piotr Sawko 2024년 2월 7일
편집: Infinite_king 2024년 2월 9일
I'm generating code for a simple logic as per below:
Because in the model settings I'm supporting 'non-finite numbers', multiple functions are generated to deal with those. All are inside the model.c file which is exactly what I want - all self contained in a single file. All but one of those functions are marked as static which makes sense, since the model.h doesn't export any of them. However, for one function (and also some variables) 'extern' specifier is used. I don't understand why, since none of those functions/variables are present in the header file. This creates a headache for me, since if I generate code for two models independently I end up with two functions, named exactly the same, in each of the model.c files. The linker isn't particularly happay about it.
Here's the code:
#include "untitled1.h"
#define NumBitsPerChar 8U
extern real_T mymodel_rt_powd_snf(real_T u0, real_T u1);
static real_T rtGetInf(void);
static real32_T rtGetInfF(void);
static real_T rtGetMinusInf(void);
static real32_T rtGetMinusInfF(void);
static real_T rtGetNaN(void);
static real32_T rtGetNaNF(void);
extern real_T rtInf;
extern real_T rtMinusInf;
extern real_T rtNaN;
extern real32_T rtInfF;
extern real32_T rtMinusInfF;
extern real32_T rtNaNF;
Any idea how to make all functions/variable file scoped (except obviosuly _step and _initialise functions)?
Below are the relevant settings:
UtilityFuncGeneration 'Auto'
SupportNonFinite 'on'
ERTFilePackagingFormat 'Compact'
PreserveExternInFcnDecls 'on'
PreserveStaticInFcnDecls 'on'

답변 (1개)

Infinite_king
Infinite_king 2024년 2월 9일
편집: Infinite_king 2024년 2월 9일
Hi Piotr Sawko,
The function 'mymodel_rt_powd_snf' contains the main logic of the model and may have been generated as an external function for direct access.
Case 1:-
If you want to use this model in different models, then generate code separately for these models and integrate the generated code. Then you can try the following suggestions
  1. The best way is to integrate the models and then generating code for the combined model.
  2. Edit the generated code to change the scope of the function.
Case 2:-
If you want to use this model multiple times in a same model as a sub model, then you can safely use the model multiple times, this will not cause any problem.
Some general guidelines to generate code for multiple models that can be integrated later:
  1. Utilize techniques such as model reference hierarchy or interface code for multiple models using a common harness program.
  2. Pay attention to global data, configuration parameter settings, code reuse, and scheduling complexities when combining code for different models.
  3. Use unidirectional signal connections between models to manage data flow and timing.
  4. Ensure consistent configuration of solver modes and handling of continuous states if applicable.
  5. Manage data logging and external mode support appropriately for each model in the program.
  6. Generate code for each model, set system target files consistently, compile, combine makefiles, and create a combined simulation engine.
For more information refer the following resorce :- https://www.mathworks.com/help/rtw/ug/combined-models.html

카테고리

Help CenterFile Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by