MATLAB: Do I get an error about “Unrecognized use” in Microsoft Visual Studios when I try to compile code generated using the Pack And Go utility for Real-Time Workshop 7.4 (R2009b)

gopackpackngosimulink coder

I compile the F14 demo model for Pack And Go with the following command as outlined in the documentation here;
<http://www.mathworks.com/access/helpdesk/help/toolbox/rtw/ug/bqufw6y.html>
 
set_param('rtwdemo_f14', 'PostCodeGenCommand',...
'packNGo(buildInfo, {''packType'' ''hierarchical''})');
When I try to compile this in Microsoft Visual Studios I get an error that points to the following code in the simstruc.h
 
#elif defined(MATLAB_MEX_FILE)
/* Used in mex function that is NOT an S-Function mex
*/
/*
* Currently, plain mex functions will be treated as if they are
* normal sfunctions.
*
# undef SS_MEX
# define SS_MEX (1)
*/
# undef SS_SFCN_NORMAL
# define SS_SFCN_NORMAL (1)
#else
# error Unrecognized use.
#endif

Best Answer

This occurs because when you compile the code from Real-Time Workshop, a Make file is created. This defines some #defines which are not executed correctly when you compile without the Make file (from Microsoft Visual Studios). In order to do this, you need to open the code in Microsoft Visual Studios via the MAK file generated specifically for this use from the correct Real-Time workshop TLC file . Detailed steps are listed below.
1) From your model, be sure to select configuration parameters -> Real-time Workshop -> Target Selection -> Browse and select the GRT.tlc target that says it is specifically for Microsoft Visual Studios. (this is the one right below the GRT for Generic Target).
2) Set your pack and go on the model as the doc says
 
set_param(your_model, 'PostCodeGenCommand','packNGo(buildInfo, {''packType'' ''hierarchical''})');
3) Build the code to the single ZIP file from RTW -> Build
4) Move your ZIP to the target directory / computer and unzip accordingly.
5) Now you will need to right click -> open with Visual Studios the MAK file (different than the MK file built using Generic GRT target). Continue through with the "conversion" that Microsoft Visual Studios prompts for when you open this and this will create the project.
6) At this point, there is one thing left to make this work, and that will be to correct the paths to all of the directories that hold all of the .h files that the MAK file just set up. Since you have moved all of these Files from the Pack And Go Zip, you will need to re-set these to the new locations (on this new computer / target).
From the visual studios project, go to the project in the Solution Explorer -> Right click -> Properties. From Configuration Properties -> set the "Additional Include Directories" to include the multiple folders that contain any of the code provided by the Pack and Go unzip. There should be about 6-8 or so of them.
At this point you should be able to Build this target using the Microsoft visual studios IDE.