如何使用matlab生成的代码

时间:2016-05-05 07:32:38

标签: c matlab matlab-coder

我想在Matlab中使用C-coder。这将m代码转换为C代码。 我使用一个添加5个数字的简单函数。 生成代码时,会有很多C文件和H文件。 当然,您可以选择所需的代码并将其导入代码中,但这不是本练习的重点,因为当matlab代码变得更加困难时,这将不再可能。

Matlab提供了一个main.c文件和一个.mk文件。

/* Include Files */
#include "rt_nonfinite.h"
#include "som.h"
#include "main.h"
#include "som_terminate.h"
#include "som_initialize.h"

//Declare all the functions

int main(int argc, const char * const argv[]){
(void)argc;
(void)argv;

float x1=10;
float x2=20;
float x3=30;
float x4=40;
float x5=50;
float result;

/* Initialize the application.
 You do not need to do this more than one time. */
som_initialize();


main_som();

result=som(x1,x2,x3,x4,x5);
printf("%f", result);

 som_terminate();
 return 0;

}

当我使用

在树莓派上运行时
gcc -o test1 main.c

它给了我对所有函数的未定义引用...... 任何想法出了什么问题?

2 个答案:

答案 0 :(得分:1)

您必须使用生成的makefile(mk文件)构建它,以便它与正确的Matlab库链接 - 这些库是定义这些函数的地方:

$ make -f test.mk

答案 1 :(得分:0)

您还需要与main.c一起编译其他C文件。如果main.c与生成的代码位于同一目录中,您应该能够:

gcc -o test1 *.c

如果生成的代码在另一个目录中,那么您可以执行以下操作:

gcc -o test1 /path/to/code/*.c -I/path/to/code main.c