Redian新闻
>
Which library include gethostbyname?
avatar
Which library include gethostbyname?# Unix - 噫吁兮,危乎高哉
C*n
1
SHIT, I can't link.
I use CC myprogram.cc,
I got error because "gethostbyname" can't be find.
I include the "netdb.h", but what's the library should I link to?
I tried
CC myprogam.cc -lsocket
won't work.
Thanks.
avatar
O*e
2
-lnsl
man gethostbyname
Reformatting page. Please Wait... done
Networking Services Library Functions gethostbyname(3NSL)
NAME
gethostbyname, gethostbyname_r, gethostbyaddr,
gethostbyaddr_r, gethostent, gethostent_r, sethostent,
endhostent - get network host entry
SYNOPSIS
cc [ flag ... ] file ... -lnsl [ library ... ]
#include
struct hostent *gethostbyname(const char *name);
struct hostent *gethostbyname_r(const char *n

【在 C****n 的大作中提到】
: SHIT, I can't link.
: I use CC myprogram.cc,
: I got error because "gethostbyname" can't be find.
: I include the "netdb.h", but what's the library should I link to?
: I tried
: CC myprogam.cc -lsocket
: won't work.
: Thanks.

avatar
X*r
3
What's your OS?
Check your man page first.
on SunOS 5.6, it's -lxnet

【在 C****n 的大作中提到】
: SHIT, I can't link.
: I use CC myprogram.cc,
: I got error because "gethostbyname" can't be find.
: I include the "netdb.h", but what's the library should I link to?
: I tried
: CC myprogam.cc -lsocket
: won't work.
: Thanks.

avatar
kb
4
add -lnsl.
see man page of gethostbyname, you will find this.

【在 C****n 的大作中提到】
: SHIT, I can't link.
: I use CC myprogram.cc,
: I got error because "gethostbyname" can't be find.
: I include the "netdb.h", but what's the library should I link to?
: I tried
: CC myprogam.cc -lsocket
: won't work.
: Thanks.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。