How do I properly call this function in my MATLAB Coder-generated dll?

9 views (last 30 days)
I am currently working on a simulation which I have compiled into a dll using Matlab Coder. Now I want to test if the dll is working fine but I cannot access the compiled function using calllib. A part of this function is to load an object from a .mat file which contains all the simulation properties and methods, minus the input of course. The executing script is:
fullpathToHeader = 'headerpath\function_Sim.h';
fullpathToDll = 'dll_path\library_Sim.dll';
[notfound,warnings] = loadlibrary(fullpathToDll, fullpathToHeader);
dt = 1;
t0 = -5;
t_end = 20;
timer = t0:dt:t_end;
t = t0;
F_com = 1e10;
M0 = 3;
h0 = 1e4;
alpha = 5;
beta = 1;
status_PCA = 2;
status_KV = 2;
output = calllib('library_Sim','function_Sim', double(dt), ...
double(t0), ...
double(t_end), ...
double(F_com), ...
double(M0), ...,
double(h0), ...
double(alpha), ...
double(beta), ...
double(status_PCA), ...
double(status_KV))
And the error I get is:
>>"Error using calllib
No method with matching signature.
Error in test_dll (line 51)
output = calllib('library_Sim','function_Sim', double(dt), ...<<
I initially thought I had to clearly define the input types (which is why everything has double() around it) but that made 0 difference.
The header file generated for the function I am trying to call looks as follows:
/*
* function_Sim.h
*
* Code generation for function 'function_Sim'
*
*/
#ifndef FUNCTION_SIM_H
#define FUNCTION_SIM_H
/* Include files */
#include "function_Sim_types.h"
#include "rtwtypes.h"
#include <stddef.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Function Declarations */
extern void function_Sim(double dt, double t0, double t_end, double F_com,
double M0, double h0, double alpha, double beta, double status_PCA, double
status_KV, emxArray_real_T *out);
#ifdef __cplusplus
}
#endif
#endif
/* End of code generation (function_Sim.h) */
I have tried to enter the inputs directly instead of variables, I had packaged them all into a struct at one point, I had the same issue. What am I overlooking here?

Accepted Answer

Richard McCormack
Richard McCormack on 11 May 2022
Edited: Richard McCormack on 11 May 2022
Hi Jan,
Using loadlibrary on a dll generated through MATLAB Coder is not supported (see the limitations here):
For testing, you can use MEX generation and call your code from MATLAB that way.
For more verification options, please review our documentation here:
In particular, "Software-in-the-Loop Execution with the MATLAB Coder App" may be helpful.
Best,
Richard

More Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!