Linking errors with auto-generated model code containing non-inlined s-functions
Show older comments
I am trying to compile the autogenerated code from a R2017a Simulink model for real time execution on a linux target. The model contains 2 non-inlined S functions that were written a very long time ago. An equivalent simulink model made in R14a is able to auto generate and compile on the target with no issues. I have updated the model to Matlab 2017a's simulink version, and added some features.
When auto-coding, I got an error which told me I needed to manually enable support for non-inlined s-functions, so I did that, and the code generated successfuly with a few innocuous warnings. We will assume that the name of the s-functions are "foo" and "bar". When attempting to compile on the target I get the following linking errors in the top level c file i.e. "Model_that_implements_foo_and_bar.c":
undefined reference to 'foo(SimStruct_tag*)'
undefined reference to 'bar(SimStruct_tag)*'
Any help to get me past this linking error would be greatly appreciated.
The definition of the functions looks like this:
Model_that_implements_foo_and_bar_private.h:
extern void foo(SimStruct *rts);
extern void bar(SimStruct *rts);
The code surrounding each implementation of the functions looks like this:
Model_that_implements_foo_and_bar.c:
/* RWORK */
ssSetDWorkWidth(rts, 0, 2012);
ssSetDWorkDataType(rts, 0,SS_DOUBLE);
ssSetDWorkComplexSignal(rts, 0, 0);
ssSetDWork(rts, 0, &rtDWork.fooSFunction_RWORK[0]);
/* DSTATE */
ssSetDWorkWidth(rts, 1, 802);
ssSetDWorkDataType(rts, 1,SS_DOUBLE);
ssSetDWorkComplexSignal(rts, 1, 0);
ssSetDWorkUsedAsDState(rts, 1, 1);
ssSetDWork(rts, 1, &rtDWork.fooSFunction_DSTATE[0]);
}
/* registration */
foo(rts); % ** this line throws the error **
sfcnInitializeSizes(rts);
sfcnInitializeSampleTimes(rts);
/* adjust sample time */
ssSetSampleTime(rts, 0, 0.002);
ssSetOffsetTime(rts, 0, 0.0);
sfcnTsMap[0] = 0;
Additionally there are some very suspicious warnings that are saying many of the lines of code with calls to ssSet functions have no effect, for example:
statement has no effect 'ssSetDWork(rts, 0, &rtDWork.SFunctionfoo_RWORK[0])'
statement has no effect 'ssSetInputPortBufferDstPort(rts, 0, -1)'
Answers (0)
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!