【发布时间】:2018-09-03 12:38:21
【问题描述】:
我是 C 中这个头文件的新手。
我正在尝试使用 makefile 将我的代码文件一起编译。每个头文件有 2 个头文件和 2 个 c 文件,还有 1 个 main.c 文件。
我有 main.c 这是我的主要功能,它有“#include”dict2.h“”。 dict1 和 dict2 标头有些相同。不同的是dict2有额外的链表功能。
-bash-4.1$ make dict1
gcc -Wall -c main.c -o main.o -g
In file included from main.c:6:
dict2.h:1: warning: useless storage class specifier in empty declaration
dict2.h:8: warning: useless storage class specifier in empty declaration
dict2.h:21: error: expected declaration specifiers or '...' before 'record_t'
dict2.h:24: error: expected declaration specifiers or '...' before 'record_t'
dict2.h:42: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
dict2.h:45: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
dict2.h:48: error: expected ')' before '*' token
make: *** [main.o] Error 1
我的 dict2.h 函数看起来像这样:
typedef struct record_t;
typedef struct node_list node_list_t;
struct node_list;
typedef struct list_t;
typedef struct node node_t;
struct node;
node_t* transform_input(FILE *finput, node_t *root);
//line 21
node_t* bst_insert(node_t *root, record_t* data);
//line 24
node_t* bst_create_node(node_t* root, record_t* data);
node_t* bst_search(node_t* root, char* name_keyword, int* numcomparison);
void search_then_print(char* keyword, node_t* root, FILE* foutput, \
int* numcomparison);
void freeTree(node_t *root);
void print_record(FILE* foutput, node_t* targetnode, char* keyword,\
int* numcomparison);
//line 42
list_t *insert_at_foot(list_t *list, record_t *datarecord);
//line 45
list_t *create_empty_list(void);
//line 48
void free_list(list_t* list);
我查看了网上的讨论,但并试图修复它,但我在头文件中找不到错误。
感谢您的帮助。
【问题讨论】:
-
typedef struct record_t;?你是不是错过了什么? -
关于头文件的一些事情。首先,您应该在每个头文件中都有一个包含保护。其次,头文件应该只包含您希望在其他模块中导出和使用的函数的声明。如果
dict.c是一个模块,它应该只有dict.h的符号,它导出用于例如。main.c. -
哦,我得到了“typedef struct record_t;”在 dict2.h 的顶部,我忘了把它复制到我的问题中
-
是的,编译器正在抱怨该行。查看下一行,看看您的
typedef应该是什么样子。 -
我为每个标题和 typedef struct record_t 添加了包含保护;但后来我仍然得到错误
标签: c makefile header-files