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

时间:2014-03-19 18:26:09

标签: c++ tcp

我正在处理的项目包括以下内容

#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兼容的方法?

2 个答案:

答案 0 :(得分:1)

这与您导入标头的顺序有关!

此命令有效

User

答案 1 :(得分:-2)

使用

 #include <sys/socket.h>

in else part