MATLAB Answers

MATLAB Coder: Option "generate one file for each MATLAB file"

13 views (last 30 days)
Hello, I want to produce C/C++ standalone Code with MATLAB Coder. Although i took the option "generate one file for each MATLAB file" some MATLAB files are translated together in one C/C++ file. Is there another option to take influence on that? Kind regards Andreas

  6 Comments

Show 3 older comments
Andreas Schröffer
Andreas Schröffer on 26 Aug 2017
I tried this allready. So ist get a file for fcn2. But in fcn1 there is no call of fcn2. Fcn1 is y=x+1
I thing dividig code into single functions is the the best Way to structure and reuse your Code. If i get just one large C\C++ File with some hundrets of lines, there is noch Chance to Debug that anymore. Furthermore i think thats the Common way to write Code with many private funktions and only export some public ones.
What i don't unterstand is, that for some of the called not entry point functions a extra C-file is generated and for some not. Is there any way to influence that by some Coder Flag.
Carl
Carl on 28 Aug 2017
Thanks for following up. To prevent MATLAB Coder from inlining a function, you can use the line "coder.inline('never')". For example:
function b = fcn2(a)
coder.inline('never')
b = a + 1;
end
This will prevent fcn2 from being inlined in fcn1.
Andreas Schröffer
Andreas Schröffer on 30 Aug 2017
Thank you.
The option coder.inline('never') was exactly, what i was searching for.

Sign in to comment.

Accepted Answer

Carl
Carl on 28 Aug 2017
Possible solutions:
  1. Provide both functions as an entry-point function
  2. Use the coder.inline flag to control whether a function gets inlined (see documentation below)
https://www.mathworks.com/help/simulink/slref/coder.inline.html

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by