包括 <netinet/tcp_var.h> 错误:字段的类型不完整'struct xsocket'

including <netinet/tcp_var.h> error: field has incomplete type 'struct xsocket'

本文关键字:类型 字段 struct xsocket gt netinet lt tcp 包括 var 错误      更新时间:2023-10-16

我正在工作的项目有以下包括

#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>