Using multiple copies of the same MATLAB Function Block

Hello,
I'm trying to use the same MATLAB Function block multiple times in the same Simulink model. These duplicate instances of the MATLAB function are inside a library. I think this is a key piece of information for this issue.
If I have one copy of the block, the model compiles just fine. If I add a second MATLAB function block, identical to the first one, I get a conflicting declaration error that happens when the S-Functions are being generated for the MATLAB function blocks:
"C:\Program Files\MATLAB\R2020a\bin\win64\mex.exe" -R2018a -c -DMATLAB_MEX_FILE -I"C:\dev\Simulink\Models\controller\slprj\_sfprj\controller\lib_controller\sfun\src" -I"C:\dev\Simulink\Models\controller" -I"C:\Program Files\MATLAB\R2020a\extern\include" -I"C:\Program Files\MATLAB\R2020a\simulink\include" -I"C:\Program Files\MATLAB\R2020a\simulink\include\sf_runtime" -I"C:\Program Files\MATLAB\R2020a\stateflow\c\mex\include" -I"C:\Program Files\MATLAB\R2020a\rtw\c\src" -I"C:\dev\Simulink\Models\Controller\slprj\_sfprj\controller\lib_controller\sfun\src" CFLAGS="$CFLAGS " lib_controller_sfun.cpp Building with 'MinGW64 Compiler (C++)'. In file included from C:\dev\Simulink\Models\Controller\slprj\_sfprj\controller\lib_controller\sfun\src\c2_lib_controller.h:42:0, from C:\dev\Simulink\Models\Controller\slprj\_sfprj\controller\lib_controller\sfun\src\lib_controller_sfun.cpp:5: C:\dev\Simulink\Models\controller/interface_parameters.h:15:3: error: conflicting declaration 'typedef struct CURVE_POINT CURVE_POINT' } CURVE_POINT; ^~~~~~~~~~~ In file included from C:\dev\Simulink\Models\Controller\slprj\_sfprj\controller\lib_controller\sfun\src\c1_lib_controller.h:42:0, from C:\dev\Simulink\Models\Controller\slprj\_sfprj\controller\lib_controller\sfun\src\lib_controller_sfun.cpp:4: C:\dev\Simulink\Models\controller/interface_parameters.h:15:3: note: previous declaration as 'typedef struct CURVE_POINT CURVE_POINT' } CURVE_POINT; ^~~~~~~~~~~
How could this be prevented? I thought it was possible to use multiple instances of the same MATLAB Function block without a problem.

댓글 수: 3

The error seems to originate from these includes in "library_sfun.cpp":
#include "c1_lib_controller.h"
#include "c2_lib_controller.h"
Each of these headers refers to one instance of the MATLAB Function block. Each of them has a "#include interface_parameters.h", which is where I define the structs for my model parameters. Since it's being included twice, I get this error.
How to prevent this?
Can you protect the code with an #ifndef ?
#ifndef interface_parameters_h
#define interface_parameters_h
then the code
#endif
maiaL
maiaL 2020년 7월 13일
편집: maiaL 2020년 7월 13일
All these files are generated code from the compilation of the main model, I don't think I'm supposed to edit them.

댓글을 달려면 로그인하십시오.

 채택된 답변

maiaL
maiaL 2020년 7월 13일

0 개 추천

Fixed the issue by encapsulating the MATLAB Function block in a subsystem in the library.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2020년 7월 13일

답변:

2020년 7월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by