使用交叉编译器(arm none eabi gcc)在文件中定义外部结构
我正试图编译一个项目,其中包括一些源文件和头文件,包括一些结构定义。但当我编译时,会出现一个错误 错误:文件“uip.h”中“typedef”之前应为说明符限定符列表 我在文件中有一个名为“httpd.h”的结构 我想在另一个名为“uip.h”的文件中键入此结构使用交叉编译器(arm none eabi gcc)在文件中定义外部结构,c,C,我正试图编译一个项目,其中包括一些源文件和头文件,包括一些结构定义。但当我编译时,会出现一个错误 错误:文件“uip.h”中“typedef”之前应为说明符限定符列表 我在文件中有一个名为“httpd.h”的结构 我想在另一个名为“uip.h”的文件中键入此结构 struct uip\u conn{ uip_ipaddr_t ripaddr;/**
struct uip\u conn{
uip_ipaddr_t ripaddr;/**<远程主机的IP地址*/
u16_t lport;/**<本地TCP端口,按网络字节顺序*/
u16_t rport;/**<本地远程TCP端口,按网络顺序*/
u8_t rcv_nxt[4];/**<我们希望接下来接收的序列号*/
u8_t snd_nxt[4];/**<我们上次发送的序列号*/
u16_t len;/**<先前发送的数据长度*/
u16_t mss;/**<连接的当前最大段尺寸*/
u16_t initialmss;/**<连接的初始最大段大小*/
u8_t sa;/**<重传超时计算状态变量*/
u8_t sv;/**<重传超时计算状态变量*/
u8_t rto;/**<重传超时*/
u8_t tcpstateflags;/**
有人能帮忙吗?在
结构定义中不能有typedef
语句。将其吊离结构
,或者根本不使用类型定义
:
// Option #1: Hoisting
typedef struct httpd_state uip_tcp_appstate_t;
struct uip_conn {
...
uip_tcp_appstate_t appstate;
};
// Option #2: No typedef
struct uip_conn {
...
struct httpd_state appstate;
};
当我将typedef
提升到struct
外部时,出现以下错误:错误:字段“appstate”的类型不完整。当我没有使用“typedef”时,会出现相同的错误。任何建议。@GauravPathak:您需要#包括定义struct http_state
(httpd.h
)的头文件,然后才能使用它。您还需要确保没有任何循环依赖关系——如果uip.h
包括httpd.h
,则httpd.h
不能包括uip.h
。
struct uip_conn {
uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */
u16_t lport; /**< The local TCP port, in network byte order. */
u16_t rport; /**< The local remote TCP port, in network order. */
u8_t rcv_nxt[4]; /**< The sequence number that we expect toreceive next. */
u8_t snd_nxt[4]; /**< The sequence number that was last sent by us. */
u16_t len; /**< Length of the data that was previously sent. */
u16_t mss; /**< Current maximum segment size for the connection. */
u16_t initialmss; /**< Initial maximum segment size for the connection. */
u8_t sa; /**< Retransmission time-out calculation state variable. */
u8_t sv; /**< Retransmission time-out calculation state variable. */
u8_t rto; /**< Retransmission time-out. */
u8_t tcpstateflags; /**< TCP state and flags. */
u8_t timer; /**< The retransmission timer. */
u8_t nrtx; /**< The number of retransmissions for the last segment sent*/
/** The application state. */
**typedef struct httpd_state uip_tcp_appstate_t;
uip_tcp_appstate_t appstate;**
} __attribute__((packed));
// Option #1: Hoisting
typedef struct httpd_state uip_tcp_appstate_t;
struct uip_conn {
...
uip_tcp_appstate_t appstate;
};
// Option #2: No typedef
struct uip_conn {
...
struct httpd_state appstate;
};