首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

cygwin gcc编译连接出错,说是 undefined reference to `getaddrinfo'解决方法

2012-03-12 
cygwin gcc编译连接出错,说是 undefined reference to `_getaddrinfoconfigure结果出现:configure:WARNIN

cygwin gcc编译连接出错,说是 undefined reference to `_getaddrinfo'
configure结果出现:configure:
WARNING: winsock2.h: present but cannot be compiled
configure: WARNING: winsock2.h: check for missing prerequisite headers?
configure: WARNING: winsock2.h: see the Autoconf documentation
configure: WARNING: winsock2.h: section "Present But Cannot Be Compiled"
configure: WARNING: winsock2.h: proceeding with the compiler's result
gcc版本为:3.4.4
.libs/mms.o:mms.c:(.text+0x1dc0): undefined reference to `_getaddrinfo'
.libs/mms.o:mms.c:(.text+0x1e6a): undefined reference to `_freeaddrinfo'
.libs/mms.o:mms.c:(.text+0x1e93): undefined reference to `_freeaddrinfo'
objdump -t 结果:
[ 76](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _srand
[ 77](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _libiconv
[ 78](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _strlen
[ 79](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _close
[ 80](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _freeaddrinfo
[ 81](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _connect
[ 82](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _socket
[ 83](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _getaddrinfo
[ 84](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _sprintf
[ 85](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _memset
[ 86](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _write
[ 87](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _strerror
[ 88](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _read
[ 89](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 ___errno
[ 90](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _select
[ 91](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _strcasecmp
[ 92](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _memcmp
[ 93](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 ___getreent
[ 94](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _fprintf
[ 95](sec 0)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x00000000 _getenv
相关源代码:
static int fallback_io_tcp_connect(void *data, const char *host, int port)
{
  struct addrinfo *r, *res;
  struct addrinfo hints;
  char port_str[16];
  int i, s;

  memset(&hints, 0, sizeof(hints));
  hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICSERV;
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = IPPROTO_TCP;

  sprintf(port_str, "%d", port);
  i = getaddrinfo(host, port_str, &hints, &res);
  if (i != 0) {
  lprintf("unable to resolve host: %s\n", host);
  return -1;
  }

  for (r = res; r != NULL; r = r->ai_next) {
  s = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
  if (s != -1) {
  if (connect(s, r->ai_addr, r->ai_addrlen) != -1) {
  freeaddrinfo(res);
  return s;
  }
  closesocket(s);
  }
  }

  freeaddrinfo(res);
  return -1;
}
我怀疑可能是configure的原因,但我不知道怎么弄,请高手解答。

[解决办法]
cygwin而且gcc还是v3

那么你的cygwin版本是1.5么

我记得原来1.5的头文件虽然有getaddrinfo的声明,但没有实现它

试试1.7的较新版本

或者找他第三方的实现库,比如这个貌似可以,我没试过
http://www.sra.co.jp/people/m-kasahr/getaddrinfo/

热点排行