Enums redefinition Error in code generation

3 views (last 30 days)
shimaa kamel
shimaa kamel on 4 May 2021
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

Answers (1)

Shiva Kalyan Diwakaruni
Shiva Kalyan Diwakaruni on 10 May 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.

Community Treasure Hunt

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

Start Hunting!

Translated by