How can I use MATLAB Coder to create a library where I can call each function individually?

2 views (last 30 days)
I have a "main" function I want to compile, and a number of supporting functions that also need compilation, as well, via Coder. The support functions are called by e/o, as well as by the main function.
For the sake of numeric unit testing, I need the resulting library/ies to allow access to each of the functions separately.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Aug 2017
First, disable function inlining to ensure every function has the code generated in a separate file. To accomplish this, please add the following to the first line in the function definition of every function:
coder.inline('never');
Now that every function will be generated in a separate file, the functions need to be each added to the library. The library will have have an entry for every function that is marked as an Entry-Point Function. To mark functions as such, please use the 'Add Entry-Point Function' button on the second page of the MATLAB Coder wizard, and generate the code again. Every function will now be generated in a separate file and will be callable through the library.
If you want to use the command line "codegen" instead, see the following example:
% Generate code and build a DLL
% In this example, there are three functions defined in separate files
% "main_function" takes no arguments, "support_1" takes a
% constant and "support_2" takes two constants
% The library will have entry points to all functions included
codegen -config:dll main_function support_1 -args {100} support_2 -args {1,5}

More Answers (0)

Categories

Find more on Generating Code in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!