我在Suse11下面用GCC4.3.4编译很小的一个程序:
#include<stdio.h>
#include<netdb.h>
extern int h_error;
int main(void){
hostent* p1=gethostbyname("127.0.0.1");
printf("%s\n",hstrerror(h_error));
return 0;
}
但是编译报错:
g++ t.cpp
/tmp/cc3OdLYH.o: In function `main':
t.cpp:(.text+0x18): undefined reference to `h_error'
collect2: ld returned 1 exit status
问题是,man gethostbyname提示:
SYNOPSIS
#include <netdb.h>
extern int h_errno;
struct hostent *gethostbyname(const char *name);
分明是存在h_error这个全局变量的啊