c - 使用 CodeBlocks IDE 在 C 中出现 undefined reference 错误

标签 c codeblocks

我只是在玩代码块并编写了一个非常简单的程序,但是我得到了 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 并选择属性并转到构建选项卡,我发现编译文件和链接文件的选项没有被勾选。谢谢

最佳答案

enter image description here
参见上图并与您的项目进行比较。仅与红色圆圈进行比较。忽略剩余的(剩余的是我的项目/作业) 在 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/

相关文章:

c - Posix 线程消费者无法正确打印

c - 这是什么意思? #define TIMER_PASTE_B(lft,t,rgt) lft##t##_##rgt

c - 使用指针到指针的方法读取和打印矩阵

c++ - 无法打开输出文件,权限被拒绝

c++ - 为什么我不能使用 C++ 在 Mac 上为 x86_64 编译 SDL?

c - 使用 SDL 应用程序删除控制台窗口

c - _POSIX_ 与 _POSIX_SOURCE 与 _POSIX_C_SOURCE

c - sscanf 在大数上出现段错误

c++ - 使用 Code::Blocks 调试时提供程序参数

c++ - Visual Studio 错误。它在 CodeBlocks 中工作...要求 const