MATLAB: Do I get an error when I use the S-Function builder in 64-bit Simulink with the Windows SDK 7.1 Compiler

simulink

When attempting to build an s-function using the fixed-point data type I receive an error. I have checked the mex setup options and as far as I can tell everything is configured correctly.
I have used this exact s-function builder using 32-bit version of Matlab 2012a. However, when I use the 64-bit version of Matlab 2012a I get an error. I have also tried with 2012b and 2013a 64-bit version and receive the same error.
 
An unexpected error occurred during compilation. Please verify the following:
-The MEX command is configured correctly. Type 'mex -setup' at
MATLAB command prompt to configure this command.
-The S-function settings in the Initialization or Libraries tab were entered incorrectly.
(i.e. use comma separated list for the library/source files)
-If S-Function Builder dialog box in an invalid state, please restart
MATLAB before using this dialog further.

Best Answer

This is a bug in MATLAB 8.0 (R2012b), 8.1 (R2013a) and 8.2 (R2013b). The development team will consider fixing this issue in a future release of MATLAB.
What seems to be happening is that although the SDK 7.1 is one of the supported compilers, the S-Function builder does not seem to be able to detect it.
You have two workarounds:
1) Use mex -setup to select another one of our supported compilers. If you are using a 64 bit version of MATLAB, you could use Visual Studio Professional 2008, 2010 and 2012. If you are using a 32 BIT, you can use 'lcc-win32 v2.4.1', which is a free compiler that we ship along with our software.
I understand the 64 bit compilers only come with Visual Studio Professional, which is a paid software. If you do not have access to the above compilers, you can use the 2nd workaround.
2)
- Select the Microsoft Windows SDK 7.1 compiler, and try to build the C-MEX S-function from the S Function Builder.
- You will get an error, however MATLAB does not delete the C files generated by the S Function Builder.
- In your 'Working Directory', you should have an 'rtwmakecfg.m' file, along with 2 '.c' files: 'yourSFunctionName.c' and 'yourSFunctionName_wrapper.c'
- Keeping your simulink model open, run rtwmakecfg.m on the MATLAB Command Window by using the following command:
>>rtwMKCFG_out=rtwmakecfg
- Now run the following command to generate the C-MEX S-Function
>>mex(['-I' rtwMKCFG_out.includePath{:}], ['-I' rtwMKCFG_out.sourcePath{:}], ['-L' rtwMKCFG_out.linkLibsObjs{:}], 'yourSFunctionName.c', 'yourSFunctionName_wrapper.c', '-lfixedpoint')
If rtwMKCFG_out has empty outputs for 'includePath' and 'LikeLibsObjs', you can simply type:
>>mex( 'yourSFunctionName.c', 'yourSFunctionName_wrapper.c', '-lfixedpoint').
You should now be able to run your model, as the MEX file for the S-Function that you created with the builder can be found.