日期:2014-05-16  浏览次数:21281 次

`socklen_t' has not been declared
我在SunOS上编译一个东西,出现下面的错误:

In file included from /data03/OBGRP/ob60/ob_rel/include/public/common/base/base_func.h:23,
  from /data03/OBGRP/ob60/ob_rel/include/public/common/sdlbuffer/sdl_basic_objs.h:19,
  from /data01/JFGRP/wangyl11/work/openbilling60/mediation/codec/sdl/codec_sdl_c.h:16,
  from ../src/realtime.h:5,
  from ../src/socket_for_tcpserver.cpp:10:
/usr/include/arpa/inet.h:69: error: `socklen_t' has not been declared
/usr/include/arpa/inet.h:72: error: `in_addr_t' does not name a type
/usr/include/arpa/inet.h:74: error: `in_addr_t' does not name a type
/usr/include/arpa/inet.h:75: error: variable `in_addr inet_makeaddr' has initializer but incomplete type
/usr/include/arpa/inet.h:75: error: `in_addr_t' was not declared in this scope
/usr/include/arpa/inet.h:75: error: `in_addr_t' was not declared in this scope
/usr/include/arpa/inet.h:76: error: `in_addr_t' does not name a type
/usr/include/arpa/inet.h:77: error: `in_addr_t' does not name a type
/usr/include/arpa/inet.h:75: error: storage size of `inet_makeaddr' isn't known

上面的说未定义的都可以在/usr/include/netinet/in.h中找到,其中socklen_t在两个文件中定义过:netinet/in.h和sys/socket.h;
在netinet/in.h中有如下的描述:
/*
 * The socklen definitions are reproduced here from sys/socket.h so as to
 * not introduce that namespace into existing users of netinet/in.h.
 */

在sys/socket.h中有如下的描述:
/*
 * The socklen definitions are reproduced in netinet/in.h for the inet6_
 * functions. Exposing all of sys/socket.h via netinet/in.h breaks existing
 * applications and is not required by austin.
 */

在这个文件 /usr/include/arpa/inet.h 中:
#if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
#include <sys/socket.h>
#endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */

#include <netinet/in.h>
#if defined(_XPG4_2) && !defined(__EXTENSIONS__)
#include <sys/byteorder.h>
#endif /* defined(_XPG4_2) && !defined(__EXTENSIONS__) */



------解决方案--------------------
需要指明 defined(__xx__) 类的东西么?
------解决方案--------------------

#include <sys/socket.h>

------解决方案--------------------
你就不能试试吗。

先看看标准怎么说的吧!

The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group
NAME

sys/socket.h - Internet Protocol family 

SYNOPSIS



#include <sys/socket.h>

DESCRIPTION

<sys/socket.h> makes available a type, socklen_t, which is an unsigned opaque integral type of length of at least 32 bits. To forestall portability problems, it is recommended that applications should not use values larger than 232 - 1.
------解决方案--------------------
Unix下的TCP/IP网络编程包含以下的5个文件,在绝大多数系统都不会有问题, 

#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>


------解决方案--------------------
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

我一般就man inetaddr,粘贴上那些头文件够用。
------解决方案--------------------
哎,我也看不出问题所在