Call a C function from Matlab

20 ビュー (過去 30 日間)
Sebastian Linn
Sebastian Linn 2020 年 3 月 3 日
回答済み: Pankhuri Kasliwal 2020 年 8 月 20 日
Hello,
I am trying to call a C function form Matlab. The files are in different folders. How can I achieve that? I am using Matlab R2018b.
The C file is called main.c and its funtion to be called is int main(void). I tried something like this:
% callmain.m
function y = callmain() %#codegen
y = 0;
coder.cinclude('main.h');
y = coder.ceval('main');
end
With the following code I tried to specifiy the location of the files:
cfg = coder.config('lib');
cfg.CustomInclude = [fullfile(pwd,'Inc') ' ' fullfile(pwd,'Src')];
cfg.CustomSource = fullfile(pwd,'Src','main.c');
This line of code is supposed to generate the code:
codegen -config cfg callmain.m
The complete C code can be obtained from the following link:
I would appreciate your help!
Thanks
  17 件のコメント
Prasanna Gude
Prasanna Gude 2020 年 3 月 11 日
'TIM_HandleTypeDef' is there in the third party library "stm32f4xx_hal.h". Did you build that library? If not build that library and after that try building 'mex'.
Sebastian Linn
Sebastian Linn 2020 年 3 月 12 日
No, I did not. How do I build that library? Do you mean creating code by specifying the output to lib?

サインインしてコメントする。

回答 (1 件)

Pankhuri Kasliwal
Pankhuri Kasliwal 2020 年 8 月 20 日
Yoou can see the following documentation Link. You need to follow the steps over there to call external C function into MATLAB.
  • If you are calling a C Library function then you need to additionally generate the MEX function. You can find a detailed documentation over here.

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by