这似乎是一个已经问过的问题,但我
我的代码在
app.c
:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "adding_tasks.h"
#include "viewing_tasks.h"
#include "removing_tasks.h"
#include "completing_tasks.h"
#include "buffer_cleaning.h"
int main()
{
...
return 0;
}
我的代码来自
completing_tasks.c
:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "buffer_cleaning.h"
#include "completing_tasks.h"
void task_complete(char ***all_tasks, int *num_tasks)
{
...
}
我的
completing_tasks.h
只是为了确保正确完成并且我不是盲目的:
#ifndef COMPLETING_TASKS_H
#define COMPLETING_TASKS_H
void task_complete(char ***all_tasks, int *num_tasks);
#endif
我得到的回溯:
app.c:(.text+0x6d): undefined reference to `clear_input_buffer'
/usr/bin/ld: app.c:(.text+0x88): undefined reference to `update_task_list'
/usr/bin/ld: app.c:(.text+0xa8): undefined reference to `task_view'
/usr/bin/ld: app.c:(.text+0xc8): undefined reference to `task_remove'
/usr/bin/ld: app.c:(.text+0xe5): undefined reference to `task_complete'
collect2: error: ld returned 1 exit status
我编译这一切的方式:
gcc -o app app.c adding_tasks.c completing_tasks.c removing_tasks.c buffer_cleaning.c
问题来了:
buffer_cleaning.h
的递归吗?如果是这样,如果我在所有这些文件中都需要它,我该怎么做才能阻止它?如果需要,我准备提供更多代码片段。
这些函数并未在标头中定义,它们只是在标头中声明。
声明满足编译器的要求,因此翻译单元编译不会出错。然而,这些都是链接器错误。链接器解析单独编译的翻译单元之间的引用。
鉴于您所说的 GCC 命令行,至少不清楚为什么
task_complete
未解析(您提供源代码(尽管已省略)的唯一未定义符号。但是我们只有您的话。您应该发布整个内容)构建日志,而不仅仅是错误。