[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 737
  • Last Modified:

gethostbyname

UNIXer,

If I need to use gethostbyname in my program which is compile by gcc in SunSpace !
But I get ths following error message, so, what caI do ?

-------------------------------------------------------------------------
Undefined                       first referenced
 symbol                             in file
gethostbyname                       /var/tmp/cca000t71.o
ld: fatal: Symbol referencing errors. No output written to a.out
---------------------------------------------------------------------------------

Andrew
0
andrewyu
Asked:
andrewyu
  • 3
1 Solution
 
seedyCommented:
Man page for 'gethostbyname' states:
   cc  [ flag ... ] file ... -lnsl [ library ...]

You need to link the 'nsl' library!
Cheers,
-Seedy-

0
 
seedyCommented:
Andrewyu,

Please let me know why you rated this answer or the previous
one - 'DNS' under Unix Programming as 'C'?
Would you have liked anything else too?

you answering this would help me help others better.
Cheers.
0
 
ozoCommented:
It doesn't appear that andrewyu has ever graded any answer.
0
 
seedyCommented:
Oops!  Was this auto-graded?  How can I find the difference?
0
 
Johannne1Commented:
I got the above solution but I also had to add lsocket.

gcc -lsocket -lnsl myprogram.c
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now