Why do I receive linker errors when compiling a fixed-point Simulink S-functions?

6 views (last 30 days)
I wrote a fixed-point S-function that uses functions from the Fixed-Point S-Function API, such as:
  • ssRegisterDataTypeFxpBinaryPoint
  • ssRegisterDataTypeFxpSlopeBias
  • ssRegisterDataTypeHalfPrecision
  • ssRegisterDataTypeFxpScaledDouble
  • ssRegisterDataTypeFxpFSlopeFixExpBias
  • ssFxpSetU32BitRegionCompliant
  • ssFxpGetU32BitRegionCompliant
  • ssFxpSetU32BitRegion
  • ssFxpGetU32BitRegion
When I compile the S-function using MEX, I receive the following error:
ERROR: >> mex sfun_user_fxp_asr.c
Building with 'Microsoft Visual C++ 2022 (C)'.
Error using mex
Creating library sfun_user_fxp_asr.lib and object sfun_user_fxp_asr.exp
sfun_user_fxp_asr.obj : error LNK2019: unresolved external symbol ssRegisterDataTypeFxpBinaryPoint referenced in function mdlSetInputPortDataType
sfun_user_fxp_asr.obj : error LNK2019: unresolved external symbol ssGetDataTypeIsFxpFltApiCompat referenced in function isDataTypeSupported
sfun_user_fxp_asr.obj : error LNK2019: unresolved external symbol ssGetDataTypeStorageContainCat referenced in function isDataTypeSupported
sfun_user_fxp_asr.obj : error LNK2019: unresolved external symbol ssGetDataTypeFxpWordLength referenced in function mdlSetInputPortDataType
sfun_user_fxp_asr.obj : error LNK2019: unresolved external symbol ssGetDataTypeFxpIsSigned referenced in function mdlSetInputPortDataType
sfun_user_fxp_asr.obj : error LNK2019: unresolved external symbol ssGetDataTypeIsScalingPow2 referenced infunction isDataTypeSupported
sfun_user_fxp_asr.obj : error LNK2019: unresolved external symbol ssGetDataTypeFractionLength referenced in function mdlSetInputPortDataType
sfun_user_fxp_asr.mexw64 : fatal error LNK1120: 7 unresolved externals

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Oct 2023
Edited: MathWorks Support Team on 18 Oct 2023
To compile a fixed-point S-function, additional steps must be used compared to standard C-MEX S-functions.
1. In your S-function, include "fixedpoint.c" and "fixedpoint.h". For more information, see: 
2. Pass an extra argument, "-lfixedpoint", to the MEX command. For example:
>> mex('sfun_user_fxp_asr.c','-lfixedpoint')
Passing the extra argument should resolve the linker errors.
The documentation on that topic is located at: Creating MEX-Files

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!