MATLAB Answers

S-function for static library

10 views (last 30 days)
Dear all,
I am trying to generate S-function for static library which is built in Code composer studio using Legacy Code Tool .
I took a simple example, but get an error like this:
### Start Compiling ex_doubleit
mex('ex_doubleit.c', '-IC:\Users\User\Documents\MATLAB\DoubleItLib', 'C:\Users\Vasyl Varvolik\Documents\MATLAB\DoubleItLib\Debug\DoubleItLib.lib')
Building with 'MinGW64 Compiler (C)'.
Error using mex
C:\Users\VASYLV~1\AppData\Local\Temp\mex_111404873555618_24800\ex_doubleit.obj:ex_doubleit.c:(.text+0x2704): undefined
reference to `doubleIt'
C:\Users\VASYLV~1\AppData\Local\Temp\mex_111404873555618_24800\ex_doubleit.obj:ex_doubleit.c:(.text+0xd0): undefined
reference to `doubleIt'
collect2.exe: error: ld returned 1 exit status
Error in legacycode.LCT/compile
Error in legacycode.LCT.legacyCodeImpl
Error in legacy_code (line 103)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
Error in Legacy_Code_Tool (line 57)
legacy_code('compile', def);
My m-file:
def = legacy_code('initialize')
def.HeaderFiles = {'DoubleItLib.h'};
def.HostLibFiles = {'DoubleItLib.lib'};
def.LibPaths = {'C:\Users\User\Documents\MATLAB\DoubleItLib\Debug'};
def.Options.language = 'C';
def.SFunctionName = 'ex_doubleit';
def.OutputFcnSpec = 'void doubleIt(double u1, double y1[1])';
legacy_code('sfcn_cmex_generate', def);
legacy_code('compile', def);
The library was built successfully in Code composer project:
* DoubleItLib.h
void doubleIt(double inVa, double *outVal);
#endif /* INCLUDE_DOUBLEITLIB_H_ */
* main.c
*/
void doubleIt(double inVal, double *outVal)
{
*outVal=2*(inVal);
}
Is it enough to use just library and header?

  0 Comments

Sign in to comment.

Accepted Answer

Mark McBroom
Mark McBroom on 4 May 2020
The library you built in Code COmposer studio is for a TI processor. S-Functions are built to run on Windows ( or LInux) and therefore can only be linked to libraries built for the same platform. If you want to use the library with your s-function, you will have to compile it with the same mingw64 compiler that Simulink uses to create the S-Function.

  1 Comment

Vasyl Varvolik
Vasyl Varvolik on 4 May 2020
Totally agree. Thanks a lot!

Sign in to comment.

More Answers (0)