How to call matlab generated function from c program?

1 Ansicht (letzte 30 Tage)
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?

Akzeptierte Antwort

Darshan Ramakant Bhat
Darshan Ramakant Bhat am 15 Dez. 2020
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 Kommentar
Nanda Thanigaivelan
Nanda Thanigaivelan am 17 Dez. 2020
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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by