3
votes

I have C application which uses two static libraries. Source code for these libraries are generated and built by Simulink/MATLAB.
The problem is that Simulink generates extern non-static function
real_T rt_urand_Upu32_Yd_f_pw(uint32_T *u) for block "Uniform Random Number" into the file MyModel.c for each model. And when I include these libraries in my C application I got linker error of function redefinition.

Is there any way to change code generation process in Simulink?

1
What are you using to generate code? Simulink Coder? Embedded Coder? What target? - pmb
Are you using model referencing? - pmb
I'm using Simulink Coder with own target which is based on grt.tlc (Generic Real Time Target) - Yuriy
Regarding model referencing.. My model doesn't have any sub-models.. - Yuriy
I have changed the property 'Total number of instances allowed per top model' to Zero, and problem is still present... - Yuriy

1 Answers

2
votes

Your problem as I understand it: Your 2 libraries are generated from 2 different Simulink models that both use this block, so obviously Simulink Coder cannot know that you want to use both of them and just generates the same function twice.

Here are some proposals off the top of my head if it is OK for you to have only 1 library instead of 2.

Proposal: Put both models as model references in one top model. Generate code. Simulink Coder realizes that the block is used in both models and generates the function only once.

Proposal2: Wrap the Uniform Random Number block in a subsystem with Function packaging to a separate C file. Compile the generated source files of both models together, deleting one of the copies of the C file that you generated separately.

parameters for function packaging