MATLAB: Generation of an S-function block in simulink by integrating legacy C-code through the legacy code tool

legacy code tools-functionsimulink

Hello,
I am trying to run this code also present in the mathworks website.
def = legacy_code('initialize'); def.SourceFiles = {'doubleIt.c'}; def.HeaderFiles = {'doubleIt.h'}; def.SFunctionName = 'legacy_wrapsfcn'; def.OutputFcnSpec = 'double y1 = doubleIt(double u1)'; def.SampleTime = [-1,0]; legacy_code('sfcn_cmex_generate', def); legacy_code('slblock_generate',def); legacy_code('compile', def);
The compiler throws up an error
### Start Compiling legacy_wrapsfcn mex('legacy_wrapsfcn.c', 'D:\Sunny_sfunction\doubleIt.c', '-ID:\Sunny_sfunction') legacy_wrapsfcn.c legacy_wrapsfcn.c(40) : fatal error C1083: Cannot open include file: 'simstruc.h': No such file or directory
C:\PROGRA~1\MATLAB\R2010B\BIN\MEX.PL: Error: Compile of 'legacy_wrapsfcn.c' failed.
??? Error using ==> mex at 208 Unable to complete successfully.
Error in ==> C:\Program Files\MATLAB\R2010b\toolbox\simulink\simulink\+legacycode\@LCT\compile.p>compile at 264
Error in ==> C:\Program Files\MATLAB\R2010b\toolbox\simulink\simulink\+legacycode\@LCT\legacyCodeImpl.p>legacyCodeImpl at 84
Error in ==> legacy_code at 87 [varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
Error in ==> Sfunction_legacy1 at 31 legacy_code('compile', def);
The *.c and *.h files are in the same folder as the m-file. Could you please tell me where I am going wrong?

Best Answer

Seems related to Bug# 661855. A patch is available on that page.