无法调用extern函数

时间:2014-12-23 10:12:38

标签: c

我想将一个驻留在我的func.c文件中的函数调用到我的main.c中 这是我的func.c

#include "func.h"
int func(int i) {
return ++i ;
}

这是我的头文件func.h

int func(int i);

这是我的主要代码:main.c

#include <stdio.h>
#include <stdlib.h>
#include "func.h"    
main()
{
   int res = func(3);
   printf("%d\n",res);  
system("pause");
}

编译主代码我得到错误:未定义引用&#39; func&#39; 我的目标是从外部文件(不是同一编译单元的一部分)调用函数。 怎么做?谢谢!

1 个答案:

答案 0 :(得分:-2)

#include <stdio.h>
#include <stdlib.h>
#include "func.h"    // change ( since func.h is not a slandered header file its a user define header file)  
main()
{
   int res = func(3);
   printf("%d\n",res);  
system("pause");
}