【发布时间】:2012-05-08 14:01:45
【问题描述】:
好的,我一直在尝试使用这个最长的时间,但我似乎无法让它正常工作。我有三个文件,main.c、hello_world.c 和 hello_world.h。无论出于何种原因,它们似乎都不能很好地编译,我真的不知道为什么......
这是我的源文件。首先 hello_world.c:
#include <stdio.h>
#include "hello_world.h"
int hello_world(void) {
printf("Hello, Stack Overflow!\n");
return 0;
}
然后是hello_world.h,简单:
int hello_world(void);
最后是 main.c:
#include "hello_world.h"
int main() {
hello_world();
return 0;
}
当我将它放入 GCC 时,我得到了:
cc main.c -o 主要 /tmp/ccSRLvFl.o:在函数“main”中: main.c:(.text+0x5): undefined reference to `hello_world' collect2: ld 返回 1 个退出状态 make: *** [main] 错误 1谁能帮帮我?我真的坚持这一点,但我 99% 确定这是一个非常简单的解决方法。
【问题讨论】:
标签: c gcc header header-files undefined-reference