MATLAB: Do I receive errors when building the model containing custom code in a reusable function when using Real-Time Workshop 6.6 (R2007a)

simulink coder

In my model I have an atomic subsystem which should be built as a separate function in a separate source file. This subsystem contains a Stateflow Chart which incorporates custom code. My model builds fine as long as I do not use a separate source file for my subsystem's function. However, if I choose to generate a seperate source file, I receive the following error:
C:/MATLAB74\sys\lcc\bin\lcc -c -FoChart.obj -DTID01EQ=1 -DMODEL=sf_custom -DNUMST=2 -DNCSTATES=0 -DMAT_FILE=0 -DINTEGER_CODE=0 -DONESTEPFCN=1 -DTERMFCN=1 -DHAVESTDIO -DMULTI_INSTANCE_CODE=0 -DADD_MDL_NAME_TO_GLOBALS=1 -DMT=0 -I. -I.. -IC:/MATLAB74\simulink\include -IC:/MATLAB74\extern\include -IC:/MATLAB74\rtw\c\src -IC:/MATLAB74\rtw\c\libsrc -IC:/MATLAB74\rtw\c\src\ext_mode\common -IC:/MATLAB74\rtw\c\src\ext_mode\tcpip -IC:/MATLAB74\rtw\c\src\ext_mode\serial -IC:/MATLAB74\rtw\c\src\ext_mode\custom -IC:/MATLAB74/work/sf_custom_ert_rtw -IC:/MATLAB74/work -IC:/MATLAB74/toolbox/stateflow/sfdemos -IC:/MATLAB74/rtw/c/libsrc -IC:/MATLAB74\sys\lcc\include -IC:/MATLAB74\rtw\c\ert -w -noregistrylookup Chart.c
Error Chart.c: 50 undeclared identifier `gMyStructVar'
Error Chart.c: 50 left operand of . has incompatible type `int'
Error Chart.c: 51 left operand of . has incompatible type `int'
Error Chart.c: 53 left operand of . has incompatible type `int'
Error Chart.c: 53 type error: pointer expected
Error Chart.c: 54 undeclared identifier `gMyStructPointerVar'
Error Chart.c: 54 operands of = have illegal types `int' and `pointer to int'
Error Chart.c: 55 left operand of -> has incompatible type `int'
Error Chart.c: 55 type error: pointer expected
9 errors, 0 warnings
gmake: *** [Chart.obj] Error 0x1

Best Answer

This bug has been fixed in Release 2007b (R2007b). For previous product releases, read below for any possible workarounds:
The error is received because the following statement is added to the field "Configuration Parameters -> Real-Time Workshop -> Custom code -> Include custom c-code in generated -> Source file"
#include "my_header.h"
As a workaround add the statement to the "Header file" field. The model header file is included in every subsystem source file, so there should not be any undeclared identifiers.
Related Question