<分区>
我在 dbinfo.h 中有一个简单的结构。
typedef struct {
int fields;
} dbinfo;
在我的主程序中:
#include <string.h>
...
#include "dbinfo.h"
extern dbinfo *tst_info;
void main() {
tst_info = (dbinfo *) calloc(1, sizeof(dbinfo));
dbinfo.fields = 3;
printf("\n number of fields = %d"), getnumflds());
...
}
在另一个文件 utilities.c 中我有
#include "dbinfo.h"
extern dbinfo *tst_info;
int getnumflds() {
return tst_info.fields;
}
当我尝试链接时,我在 tst_info 的 utilities.c 中得到 undefined symbol 。 如果我删除 extern,则不会得到未解析的符号,但字段的值为 0。
我做错了什么?
我只是希望能够在单独编译的其他函数中使用和更改在 main 中设置的“字段”的值。
自从我使用 C 以来已经有很长一段时间无法访问这些神经元了!