gpt4 book ai didi

c++ - 包括 错误 : field has incomplete type 'struct xsocket'

转载 作者:可可西里 更新时间:2023-11-01 02:55:15 32 4
gpt4 key购买 nike

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

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

最佳答案

这完全取决于您导入 header 的顺序!

这个命令有效

#import <sys/socketvar.h>
#import <netinet/in.h>
#import <netinet/tcp_var.h>
#import <netinet/tcp.h>
#import <sys/socket.h>

关于c++ - 包括 <netinet/tcp_var.h> 错误 : field has incomplete type 'struct xsocket' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22514928/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com