当前位置: 技术问答>linux和unix
为什么提示inet_addr,gethostbyaddr错误,头文件#include <netdb.h> #include <netinet/in.h>我已经包括,在HP机编译没有问题,现在环境
来源: 互联网 发布时间:2015-02-22
本文导语: 错误提示 undefined first referenced symbol in file inet_addr findip.o gethostbyaddr ...
错误提示
undefined first referenced
symbol in file
inet_addr findip.o
gethostbyaddr findip.o
具体代码
#include
#include
#include
#include
#include
#include
#include
extern int h_errno;
int main(int argc, char **argv)
{
struct hostent *ip;
unsigned long hostname;
if (argc != 2)
{
printf("Need to specify an IP address.n");
exit(1);
}
if ((hostname = inet_addr(argv[1])) == -1)
{
printf("Could not find %sn", argv[1]);
exit(1);
}
if ((ip = gethostbyaddr((char *)&hostname, sizeof(long), AF_INET)) != NULL)
printf("%s is %sn", argv[1], ip->h_name);
else
printf("Could not resolve %sn", argv[1]);
return 0;
}
undefined first referenced
symbol in file
inet_addr findip.o
gethostbyaddr findip.o
具体代码
#include
#include
#include
#include
#include
#include
#include
extern int h_errno;
int main(int argc, char **argv)
{
struct hostent *ip;
unsigned long hostname;
if (argc != 2)
{
printf("Need to specify an IP address.n");
exit(1);
}
if ((hostname = inet_addr(argv[1])) == -1)
{
printf("Could not find %sn", argv[1]);
exit(1);
}
if ((ip = gethostbyaddr((char *)&hostname, sizeof(long), AF_INET)) != NULL)
printf("%s is %sn", argv[1], ip->h_name);
else
printf("Could not resolve %sn", argv[1]);
return 0;
}
|
-lsocket -lnsl