[英]Undefined reference error in C using CodeBlocks IDE
我只是在玩代码块并编写一个非常简单的程序,但是我得到了未定义的引用错误...我将完全相同的代码复制到其他地方并在终端中编译它并且工作正常但是只是不起作用在代码块中。
我的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
在main.c
#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");
}
我希望这会有所帮助..因为这对我有用。
你没有确切地说明未定义的错误是什么,但我认为它与你的main()
或printhello()
函数有关。
确保您编译你的main.c和subfunc.c后,联系两者的目标文件main.obj和subfunc.obj在您的项目。 这应该自动发生在代码块中,假设您为正在构建的当前项目包含main.c和subfunc.c。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.