Hello
I'm trying to use the C-caller block to import my C-code into simulink.
now i'm trying just a simple code as below:
#include <stdio.h>
int add_fnc (int a, int b)
{
int c;
c = a +b;
return c;
}
I do as the instruction in configuration parameter to set source file.
I run the c-caller block and set the variable name is add_func.
The warning is can not find add_func.
Can you support me?

3 件のコメント

Mohammad Sami
Mohammad Sami 2020 年 3 月 19 日
I believe the keyword extern is needed.
https://www.mathworks.com/help/simulink/ug/integrate-ccode-ccaller.html
hoang tuan
hoang tuan 2020 年 3 月 19 日
Thank you.
And it seems we have to create header file to mention the function prototype first.
We can not add direct the c source code only.
Yao Ren
Yao Ren 2024 年 3 月 12 日
Yes, a C function has to be "extern" declared to be visible to a Simulink model. You can use a ".h" header file to declare the C functions.
Alternatively, without writing a new ".h" file, you can declare the C function directly in model's "Configuration paramters > Simulation Target > Custom Code > Include headers" section using following statement.
extern int add_fnc (int a, int b);

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

回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Simulink Functions についてさらに検索

製品

タグ

質問済み:

2020 年 3 月 19 日

コメント済み:

2024 年 3 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by