我有以下文件:
swaps.c#include "swaps.h"
#include "./poolutils.h"
double someFunction(struct Pool pools[]){
//do some stuff
}
int main(){
struct Pool pool1 = {"A","C",3.0,9000.0,0.0};
struct Pool pool2 = {"B","D",20.0,20000,0.0};
struct Pool pools[N];
pools[0] = pool1;
pools[1] = pool2;
double a = someFunction(pools);
}swaps.h有someFunctionpoolutils.c的签名有一些functionspoolutils.h#ifndef _POOLUTILS_H
#define _POOLUTILS_H
struct Pool {
char *token1;
char *token2;
double reserve1;
double reserve2;
double fee;
};
//signatures of poolutils.c functions
#endif在编译(gcc -c swaps.c poolutils.c)时,我会得到以下错误:
In file included from swaps.c:1:
swaps.h:4:44: error: array type has incomplete element type ‘struct Pool’
4 | double someFunction(struct Pool pools[]);现在,我确实包括了定义struct Pool的头,所以swaps.c应该知道它,但是我知道swaps.h不知道,我如何让它知道外部的定义?
(gcc版10.2.1 20210110 (Debian 10.2.1-6))
发布于 2022-05-18 10:43:08
简单地添加
#include "./poolutils.h"对于您的swaps.h,如果swaps.h需要Pool结构定义的话。
由于您已经尽职尽责地在poolutils.h中放置了包含保护,所以可以在单个编译单元中多次使用标头。
或者,交换包含的顺序;效果在这里是一样的。
#include "./poolutils.h"
#include "swaps.h"https://stackoverflow.com/questions/72287650
复制相似问题