包括 <netinet/tcp_var.h> 错误:字段的类型不完整'struct xsocket'
including <netinet/tcp_var.h> error: field has incomplete type 'struct xsocket'
我正在工作的项目有以下包括
#include <memory.h>
#include <signal.h>
#include <errno.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/socket.h>
#ifdef __linux__
# include <linux/tcp.h>
#else
# include <sys/time.h>
# include <netinet/in.h>
# include <netinet/tcp.h>
# include <netinet/tcp_var.h>
#endif
我正在64位mac上编译。当tcp_var.h包含到达时,编译器抛出以下错误:
/usr/include/netinet/in_pcb.h:192:17: error: field has incomplete type 'struct xsocket'
struct xsocket xi_socket;
^
/usr/include/netinet/in_pcb.h:192:9: note: forward declaration of 'xsocket'
struct xsocket xi_socket;
^
/usr/include/netinet/in_pcb.h:235:20: error: field has incomplete type 'struct xsocket64'
struct xsocket64 xi_socket;
^
/usr/include/netinet/in_pcb.h:235:10: note: forward declaration of 'xsocket64'
struct xsocket64 xi_socket;
^
/usr/include/netinet/in_pcb.h:245:2: error: unknown type name 'so_gen_t'
so_gen_t xig_sogen; /* current socket generation count */
^
In file included from .../tcp_client_listener.cc:52:
/usr/include/netinet/tcp_var.h:373:25: error: field has incomplete type 'struct xsocket'
struct xsocket xt_socket;
^
/usr/include/netinet/in_pcb.h:192:9: note: forward declaration of 'xsocket'
struct xsocket xi_socket;
^
/Users/Justin/Projects/smartdevicelink/SDL_Core/src/components/transport_manager/src/tcp/tcp_client_listener.cc:141:44: error: use of undeclared identifier
'TCP_USER_TIMEOUT'
setsockopt(connection_fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &user_timeout, sizeof(user_timeout));
是否有一个不同的库,我可以在#ifdef MAC_OSX
指令之间包含或一种方法来修复此前向声明并保持与其他mac的兼容性?
这完全取决于您导入标题的顺序!
this order works
#import <sys/socketvar.h>
#import <netinet/in.h>
#import <netinet/tcp_var.h>
#import <netinet/tcp.h>
#import <sys/socket.h>
use
#include <sys/socket.h>
相关文章:
- 将结构字段的类型展开为可变模板参数
- 结构体和类的不同大小(),彼此具有相同的字段类型
- 错误:字段'dateOfBirth'的类型不完整'Poco::Data::Date'
- 获取具有字段名称的 SELECT 字段类型,并带有 MariaDB C++连接器
- 无法初始化以 std::byte 作为成员类型的位字段
- 无法访问 Arduino 结构字段。错误"退出状态 1。xxxx 不命名类型"
- 在这种情况下,如何从类型 "const char*" 初始化字段?
- 确定输入"conscalc: calc"的类型时出错。不能联合编码器。具有不同字段集的结构类型
- 字段在正向声明中具有不完整的类型
- 使用固定大小类型时强制对位字段(C++14 之前)进行签名
- 返回对位字段的访问类型
- 将枚举类型保存在位字段 [dcl.enum] [class.bit] 中
- 将指向结构的指针转换为具有较少字段数的另一种结构类型
- 位字段成员的类型
- 无法汇总初始化类型结构的变量,其中包含在类模板中的位字段成员
- 在相同类型的字段上迭代
- Boost Xpressive-字段“ M_RX”具有不完整的类型
- 设计具有变体字段的文本类型类,其中可以存储一个或三个对象
- 自动复制=按值并支持多态性的适当类型的非静态字段
- 在std::set/std::map中存储具有多个不同类型字段的c++对象的有效方法