Calling an outside C function from a legacy_code block !

2 ビュー (過去 30 日間)
Franck Yin
Franck Yin 2017 年 5 月 17 日
回答済み: Franck Yin 2017 年 5 月 18 日
I have the following set of 3 files :
test.h :
#ifndef _TEST_H_
#define _TEST_H_
extern int test (int a, int b);
extern int sum (int a, int b);
#endif
test.c :
#include "test.h"
int test(int a, int b)
{
int sum;
sum = test_sum(a, b);
return sum;
}
test_sum.c :
#include "test.h"
int test_sum(int a, int b)
{
int sum;
sum = a + b;
return sum;
}
The stack is : test (to be compiled into legacy_code simulink block) > test_sum (in an external C file that's in the scope)
Now the problem is that when I try to compile the test function into a block using legacy_code, the following compilation error occurs :
error LNK2019: unresolved external symbol test_sum referenced in function test
If I copy and paste the test_sum function from test_sum.c to test.c then there's no error.
My question : How can I call another C function from within a legacy_code block ? Or is it impossible ?

採用された回答

Franck Yin
Franck Yin 2017 年 5 月 18 日
It was simple. All files must be added to the SourceFiles property.
What it was like before :
def = legacy_code('initialize');
def.SourceFiles = {'test.c'};
How it was modified in order to build properly :
def = legacy_code('initialize');
def.SourceFiles = {'test.c','test_sum.c'};

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePrepare Model Inputs and Outputs についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by