MATLAB: Do I get an error saying that I have to include a custom header in the simulation target when I use Enumeration Data Types

simulink coder

I have a library. This library uses a Simulink.IntEnumType with the getHeaderFile() method defined. So I have this directory lib_foo with lib_foo.mdl and enum_foo.m, and in R2009b all the user needed to use this library was to add the lib_foo directory to their path.
Now I'm getting an error, and the release notes for R2012a say I need to add my enum_foo.h to the Custom Code/Header file model parameter. Which presumably means I need to also provide this .h file to the Simulink user, and they need to add the directory it is in to Custom Code/Include model parameter.
I do not like doing this. How do I avoid it?

Best Answer

The errors that you are getting are actually expected behavior, and are due to the changes in Simulink introduced in R2012a. Refer to the release notes for more information:
This is why you are getting an error:
In your Enumeration definition file, you have included a function ‘getHeaderFile()’. This particular function, in the context of a Simulink model, is more important for code generation (C files, MEX files etc.) than it is for the actual simulation purposes. When you run a simple Simulink model that does not contain any Stateflow charts (such as the file ‘mdl_01.mdl’), Simulink ignores the function ‘getHeaderFile()’, as the complete definition of you Enumeration data-type has already been given in the first part of the definition file. No code generation is required to run this simple model, so it runs smoothly.
In files that have Stateflow models in them, the ‘getHeaderFile()’ function suddenly relevant. How Stateflow models work is that a C program is first generated from the chart which is then converted into a MATLAB executable file (a MEX file). The MEX file is then embedded in the Model, and the C files are deleted. For the C files to work properly, either Simulink must make or the user must provide a functional header for the Enumeration data-type.
In case your Enumeration definition file does not have the function ‘getHeaderFile()’ in it, or if the string returned by the ‘getHeaderFile()’ function is empty, the CODER will generate its own header file for this particular enumeration data type. This CODER-generated header will in most cases work perfectly if the Enum definition is well written.
I suggest that you remove the ‘getHeaderFiles()’ function entirely, as you are not really using the externally defined header in your code. If you do this the Stateflow model will know that it would have to make its own header, and while this may make your program slightly slower, it will run error free.