我只是在玩代码块并编写了一个非常简单的程序,但是我得到了 undefined reference 错误...我将完全相同的代码复制到其他地方并在终端中编译它并且工作正常,但就是没有' 在代码块中工作。
我的 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 并选择属性并转到构建选项卡,我发现编译文件和链接文件的选项没有被勾选。谢谢
最佳答案
参见上图并与您的项目进行比较。仅与红色圆圈进行比较。忽略剩余的(剩余的是我的项目/作业)
在 my_subfunction.h
写
#ifndef __MY_SUBFUNC_H__
#define __MY_SUBFUNC_H__
#include<stdio.h>
void printhello(void);
#endif
在主程序中
#include <stdio.h>
#include "my_subfunc.h"
int main()
{
printhello();
return 0;
}
和 my_subfun.c:-
#include <stdio.h>
#include "my_subfunc.h"
void printhello(void)
{
printf("hello world in function\n");
}
希望对你有帮助 因为这对我有用。
关于c - 使用 CodeBlocks IDE 在 C 中出现 undefined reference 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10169162/