MATLAB: Do I receive link errors when generating code from a S-function that was generated by the S-function Builder in Simulink 5.0 (R13)

buildercodeerrorlinkr13rtws-functionsimulinksimulink coderwrapper

I have a model 'prov1.mdl' which has an S-function builder block. The S-function builder block implements a S-function named 'prova1'. I build the S-function to generate the .dll along with other files (.tlc and wrapper). I can successfully build this model via the GRT target.
In another model 'prov2.mdl', I have an S-function block, which uses the .dll created by the S-function builder in 'prov1.mdl'. I enter 'prova1' in the S-function name dialog for the S-function block. If I try to build this model via GRT, I get the following linker errors
### Linking ...
D:\MATLAB6p5\sys\perl\win32\bin\perl D:\MATLAB6p5\rtw\c\tools\mkvc_lnk.pl prov2.lnk prov2.obj prov2_data.obj grt_main.obj rt_sim.obj rt_nonfinite.obj
ext_svr.obj updown.obj ext_svr_transport.obj ext_work.obj prova1.obj
link -debug:full -debugtype:cv /NODEFAULTLIB /INCREMENTAL:NO /PDB:NONE
/RELEASE /NOLOGO -subsystem:console,4.0 wsock32.lib libc.lib oldnames.lib
kernel32.lib ws2_32.lib mswsock.lib advapi32.lib
D:\MATLAB6p5\rtw\c\lib\win32\rtwlib_vc.lib @prov2.lnk -out:..\prov2.exe
prova1.obj : error LNK2001: unresolved external symbol _prova1_Outputs_wrapper
..\prov2.exe : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: 'link' : return code '0x460'
Stop.

Best Answer

This is the expected behavior. Because you manually entered the name of the S-function in prov2.mdl, the model does not know that the S-function is using a wrapper. You need to set the SFunctionModules parameter of the S-function block. For the prov2.mdl model, you should use the following commands at MATLAB command prompt;
set_param('prov2/S-Function', 'SFunctionModules', 'prova1_wrapper');
PLEASE NOTE: The model needs to be open when you use SET_PARAM.
For more information on S-Function modules for Real-Time Workshop builds, please refer to the documentation which can be found by typing the following in the MATLAB command line:
web([docroot '/toolbox/simulink/sfg/sfcn_rtw6.html'])
An alternate way to do this is to add the TLC macro - LibAddToModelSources to the prova1.tlc file. However, we recommend using the SFunctionModules block parameter instead of this function.
For more information see, TLC macro function in matlabroot/rtw/c/tlc/lib/utillib.tlc and also see the information on the TLC macro that can be found in the documentation by typing the following in the MATLAB command line:
web([docroot '\toolbox\rtw\tlc_ref\cp_fcnl9.html#12983'])