谁能给我解释一下?
文件a如下:
file a.c
#include <stdio.h>
#include <stdlib.h>
int fun1();
int main()
{
fun1();
return 0;
}
文件b写成:
file b.c
static int fun1();
int fun1(){
printf("fron fun1");
return 0;
}
当我尝试编译我的代码时,编译器给出了一个错误:对 fun1 的 undefined reference 。 如果我在文件 b.c 中声明 fun1 static 是什么意思?
最佳答案
如果你声明 fun1
作为static
在 b.c 中,它不会在外部可见,因此您只能在编译单元 b.c 中使用它。放下 static
.
注意:为了能够编译您的代码,您还需要添加 #include <stdio.h>
在不列颠哥伦比亚省的顶端。
关于c - 链接器说未定义的函数引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18022565/