How to call matlab generated function from c program?

2 次查看(过去 30 天)
Hi,
I am new to Matlab coder and would like to use generated functions in a project. I wrote few function implementations, say
objects = fuse_detections(frame_r, frame_c, ldr, ts)
in matlab and generated c code using Matlab coder. C code for the function implementations are generated successfully. I want to call the generated functions, by passing arguments and get values, from an other c program (which is a normal c program). I am aware that I should link generated object files (.o files) with the c program in order to use those functions. I did link .o files and .c files using ninja. How do I call those generated functions from my c program?

采纳的回答

Darshan Ramakant Bhat
You have to include the appropriate header files which contains the generated function declaration. Then you can directly call those functions from your other C/C++ coder. While compiling the entire application, you need to link the library appropriately.
Below document explains how to use the generated dll in Visual Studio and how to call it in a new C/C++ coder :
You can also generate a sample example main file and take a look at it on how to use the generated functions :
Hope this will be helpful
  1 个评论
Nanda Thanigaivelan
Nanda Thanigaivelan 2020-12-17
Thanks for your reply.
I followed the instructions for generating code as dll and used with VS 2019. It did worked as expected. Unfortunately, our deployement system is linux. So I tried to generate code using Matlab coder for library along with main file. I also assigned generate and compile option in order to create output for the generated main file. When I tried to run the complied main file, i.e., main.o, in the terminal, it returned permission denied, then tried execute as superuser, it returned command not found. I also tried chmod +x but it returned cannot execute binary file, exec format error.
I used the following configuration for code generation
cnfig = coder.config('lib');
cnfig.GenerateExampleMain = 'GenerateCodeAndCompile';
cnfig.GenerateReport = true;
codegen -config cnfig function_x1 -args params
May I know what went wrong here?
How do I solve this issue?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by