How can I use MATLAB Coder to create a library where I can call each function individually?
2 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2017-8-23
回答: MathWorks Support Team
2017-8-24
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.
采纳的回答
MathWorks Support Team
2017-8-23
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}
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Generating Code 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!