MATLAB: Do I see an error message when building models containing S-functions generated using Real-Time Workshop from models/systems that contain library blocks

simulink coder

I have two models model1 and model2 that use a library block. I have generated S-functions from parts of model1 and model2 that contain the library block (using block right click menu ->Real-Time Workshop->Build S-function):
Set of files from model1:
sfun1.c, sfun1.h. sfun1.mexw32
Set of files from model2:
sfun2.c, sfun2.h. sfun2.mexw32
I see the following error messages when I try to build a model that have the S-function blocks referring to sfun1 and sfun2:
Using ERT.TLC (Visual Studio compiler):
LINK : fatal error LNK1181: cannot open input file 'First_Part_sf.obj'
NMAKE : fatal error U1077: '"c:\program files\microsoft visual studio 8\VC\BIN\link.EXE"' : return code '0x49d'
Stop.
Using xPCTARGETERT.TLC (WATCOM compiler):
Error(F10): Macros nested too deep
Warning(W79): Makefile may be Microsoft; try /ms switch
Error(E02): Make execution terminated

Best Answer

  • This is expected. Note that generating S-function from a subsystem that uses a library block generates unique function code depending on the context of the library block. In this case sfun1 and sfun2 may have two different function signatures and bodies with the same name as that of the library block. This leads to build issues in the linking phase.
    To work around the naming conflict leading to the build error make sure the library block is not configured to produce a unique name. Leaving the function name upto to the code generation makes sure the in a referenced model instead of generating an S-function. Also consider if you can do away with the component being a library block and instead use it as a referenced model.