C 无法在此处编译我的程序或识别问题
我可以认为这些“全局”数组在某种程度上是有问题的, 但我就是不知道到底是什么问题 car.h:C 无法在此处编译我的程序或识别问题,c,gcc,cmake,clion,C,Gcc,Cmake,Clion,我可以认为这些“全局”数组在某种程度上是有问题的, 但我就是不知道到底是什么问题 car.h: #ifendf ... #define ... #define N 10000 typedef struct car { <some code here> } Car; extern Car carList[N]; <function declarations here> #endif 对“carList”的未定义引用 错误表示链接器找不到carList(和其他)的
#ifendf ...
#define ...
#define N 10000
typedef struct car { <some code here> } Car;
extern Car carList[N];
<function declarations here>
#endif
对“carList”的未定义引用
错误表示链接器找不到carList(和其他)的任何对象文件。
您使用extern
关键字定义了carList,这会告诉编译器实际数据在另一个文件中,但您不提供任何数据
要定义这些数组,您需要在[仅]一个源文件中有一行没有
extern
关键字。您的每个全局数组都需要在一个.c文件中定义。我试图在代码中搜索出现的供应商列表
,但无法在图像中搜索文本。如果code.Hellmar,请不要图像-我如何定义这些数组?它们是空的,我不允许使用malloc“定义那些数组,你需要一行带有extern
关键字”-你的意思可能是“…没有extern
关键字:该关键字总是表示声明,而不是定义。@Tsyvarev当然。修复了。谢谢。
#include "car.h"
<function definitions here>
#ifendf ...
#define ...
#define M 8000
typedef struct client { <some code here> } Client;
extern Client clientList[M];
<function declarations here>
#endif
#include "car.h"
#include "client.h"
<function definitions here>
#ifendf ...
#define ...
#define K 50
typedef struct supplier { <some code here> } Supplier;
extern Supplier supplierList[K];
<function declarations here>
#endif
#include "supplier.h"
<function definitions here>
...
/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
...