MATLAB: Am I unable to generate code with Real-Time Workshop (R12.1) when I have an C-MEX S-function created using the S-function Builder Block which contains source libraries

blockbugbuilderreal times-functionsimulinkworkshop

I am trying to use the s-function builder and then compile my model with Real-Time Workshop. My problem occurs when I try to include a library (I call it source.lib) on the libraries tab of the s-function builder.
The s-function seems to build OK, but when I try to compile my model with RTW I get an error saying it can't find source.lib.obj. Is there a solution to this issue?

Best Answer

This is a bug in R12.1 version of the Simulink S-Function Builder Block. Our development staff is aware of the issue. This will be fixed in a future release of Simulink.
The bug is in the .tlc file that is created with the s-function builder block. The workaround includes the following steps:
1. Edit the TLC file generated and remove the line:
 
%assign result = LibAddToModelSources("source.lib")
2. From the Simulation menu of your Simulink model select Simulation parameters-->Real-Time Workshop and change the make_rtw command to:
 
make_rtw EXT_LIB="<pathToLibFile>\source.lib"
Where pathToLibFile is the full path to lib file. For example:
 
make_rtw EXT_LIB="c:\temp\source.lib"
3. Next, click on the S-function Builder Block and then type:
 
set_param(gcb,'SfunctionModules','')
The above steps should allow you build the model without any errors.