c引用外部函数

来源:百度知道 编辑:UC知道 时间:2024/05/14 18:46:17
我定义一个头文件head.h:
int compute(int a, int b);
定义它的实现:head.c:
#include "head.h"
int compute(int a, int b)
{
int c;
c = a + b;
return c;
}
之后,在主文件中引用head.c中的compute函数:test.c
#include "head.h"
int main ( void )
{
int a=5, b=10;
printf("compute=%d\n", compute(a, b));
}
但提示compute函数未定义,这种引用方式不对?请指教!谢谢!

问题出在这

定义它的实现:head.c:
#include "head.h"
int compute(int a, int b)
{
int c;
c = a + b;
return c;
}

头文件是head.h

里面的内容是
int compute(int a, int b)
{
int c;
c = a + b;
return c;
}

问题出在这

定义它的实现:head.c:
#include "head.h"
int compute(int a, int b)
{
int c;
c = a + b;
return c;
}

头文件是head.h

里面的内容是
int compute(int a, int b)
{
int c;
c = a + b;
return c;
}

main函数里没返回值为什么要int的?

  方法一------编写level 2的s-function:
  这种方法比较常见,首先从help里找到s-function level 2的模板,在output函数中写下您的算法,当然这里要特别注意你的算法有多少输入输出,在s-function中也要一致。等到您自信C代码圆满后,回到Matlab命令行,mex你的C文件(编译一下,当然前提是你安装了mex,方法么,就是mex -setup,这个很简单,掠过……)。
  之后假如您的C文件OK,那么在模型路径下会生成mexw32或mexw64文件以证明编译通过,
  最后您便可以在model里使用你自定义的s-function了。
方法二------在stateflow里调用C文件:
  这种方法就是将需要调用您自