【发布时间】:2012-04-16 05:39:18
【问题描述】:
我只是在玩代码块并编写一个非常简单的程序,但我得到未定义的引用错误...我将完全相同的代码复制到其他地方并在终端中编译它并且工作正常,但只是没有不能在代码块中工作。
我的 main.c 是:
#include <stdio.h>
#include "subfunc.h"
int main()
{
printhello();
return 0;
}
然后我的 subfunc.c 是:
#include <stdio.h>
#include "subfunc.h"
void printhello(void)
{
printf("hello world in function\n");
}
然后我的 subfunc.h 是:
void printhello(void);
谢谢
更新
其实..我想通了。我右键单击文件 subfunc.c 和 subfunc.h 并选择属性并转到构建选项卡,我发现编译文件和链接文件的选项没有勾选。谢谢
【问题讨论】:
-
代码看起来不错。问题可能出在链接阶段,main.obj(编译后的 main.c)和 subfunc.obj 需要链接到一个可执行文件。
-
未定义对 what 的引用?如果可能,请始终包含确切的错误消息。
标签: c codeblocks