【发布时间】:2021-05-11 07:22:32
【问题描述】:
我可以认为这些“全局”数组在某些方面存在问题, 但我就是不知道到底是什么问题。
汽车.h:
#ifendf ...
#define ...
#define N 10000
typedef struct car { <some code here> } Car;
extern Car carList[N];
<function declarations here>
#endif
汽车.c:
#include "car.h"
<function definitions here>
client.h:
#ifendf ...
#define ...
#define M 8000
typedef struct client { <some code here> } Client;
extern Client clientList[M];
<function declarations here>
#endif
client.c:
#include "car.h"
#include "client.h"
<function definitions here>
供应商.h:
#ifendf ...
#define ...
#define K 50
typedef struct supplier { <some code here> } Supplier;
extern Supplier supplierList[K];
<function declarations here>
#endif
供应商.c:
#include "supplier.h"
<function definitions here>
编译器消息:(带有 GCC 的 CLion IDE)
...
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles/untitled1.dir/main.c.o:main.c:(.rdata$.refptr.supplierList[.refptr.supplierList]+0x0): undefined reference to `supplierList'
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles/untitled1.dir/main.c.o:main.c:(.rdata$.refptr.clientList[.refptr.clientList]+0x0): undefined reference to `clientList'
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles/untitled1.dir/main.c.o:main.c:(.rdata$.refptr.carList[.refptr.carList]+0x0): undefined reference to `carList'
collect2: error: ld returned 1 exit status
...
【问题讨论】:
-
每个全局数组都需要在一个 .c 文件中定义。
-
我试图在您的代码中搜索
supplierList的出现,但我无法在图像中搜索文本。如果代码,请不要图像。 -
Hellmar- 我该如何定义这些数组?它们是空的,我不允许使用 malloc