Enums redefinition Error in code generation
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I use Matlab 2018b to deisgn a model and generate code ,,, I need to use external enums from another .h file in the project
I have defined an enum for Simuink as follow :-
classdef exenum < Simulink.IntEnumType
enumeration
X(0)
Y(1)
X(2)
end
methods (Static)
function dScope = getDataScope()
dScope='Imported';
end
function retval = getHeaderFile()
retval = 'example.h';
end
function retVal = getDefaultValue()
retVal = exenum.X;
end
end
end
I have defined here that enum is imported,,,but while generation it gives me an error that there is a redefinition for this enum and generation aborts,,
why does it generate the enum again altought I have defined it is imported ?
Note: header file is included in sumulation target too
0 Commenti
Risposte (1)
Shiva Kalyan Diwakaruni
il 10 Mag 2021
Hi,
This error can occur when the file that contains the enum is included multiple times and it isn't wrapped with a "#ifndef ... #endif" statement. Even if it is only explicitly included once in the Custom Code section, the header file might be included by a different header file which is also included with the model, therefore including it twice. To prevent the type redefinition no matter how many times the file is included, wrap the entire contents of the header file in code such as this:
#ifndef HEADER_FILE_NAME
#define HEADER_FILE_NAME
...
...
#endif
Hope it helps.
0 Commenti
Vedere anche
Categorie
Scopri di più su Simulink Functions in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!