compiling socket program
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > compiling socket program




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    compiling socket program  
ICN_OK


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-05 02:01 AM

When I compile a client program,
I encountered error and I fixed that problem after I was told about
-lsocket option.

> CC cl.cpp

Undefined                       first referenced
symbol                             in file
gethostbyname                       cl.o
socket                              cl.o
connect                             cl.o

However, I still encounter an error like this:

> CC cl.cpp -lsocket
Undefined                       first referenced
symbol                             in file
gethostbyname                       cl.o  (symbol belongs to implicit
dependency /usr/lib/libnsl.so.1)


function socket() and connect() are fine,
but gethostbyname() is still not linked.

How can I fix the problem?






[ Post a follow-up to this message ]



    Re: compiling socket program  
David Schwartz


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-05 02:01 AM


"ICN_OK" <cobra1030@hanmail.net> wrote in message
news:1127419069.624180.230360@g44g2000cwa.googlegroups.com...

> When I compile a client program,
> I encountered error and I fixed that problem after I was told about
> -lsocket option.
> 
>
> Undefined                       first referenced
> symbol                             in file
> gethostbyname                       cl.o
> socket                              cl.o
> connect                             cl.o
>
> However, I still encounter an error like this:
> 
> Undefined                       first referenced
> symbol                             in file
> gethostbyname                       cl.o  (symbol belongs to implicit
> dependency /usr/lib/libnsl.so.1)
>
>
> function socket() and connect() are fine,
> but gethostbyname() is still not linked.
>
> How can I fix the problem?

How about '-lnsl' as the error message explains.

DS







[ Post a follow-up to this message ]



    Re: compiling socket program  
Maurizio Loreti


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-05 02:01 AM

"ICN_OK" <cobra1030@hanmail.net> writes:

> When I compile a client program,
> I encountered error and I fixed that problem after I was told about
> -lsocket option.
> 
>
> Undefined                       first referenced
>  symbol                             in file
> gethostbyname                       cl.o
> socket                              cl.o
> connect                             cl.o
>
> However, I still encounter an error like this:
> 
> Undefined                       first referenced
>  symbol                             in file
> gethostbyname                       cl.o  (symbol belongs to implicit
> dependency /usr/lib/libnsl.so.1)
>
>
> function socket() and connect() are fine,
> but gethostbyname() is still not linked.
>
> How can I fix the problem?

-lsocket -lnsl , I suppose.

--
Maurizio Loreti                         [url]http://www.pd.infn.it/~loreti/mlo.html[/ur
l]
Dept. of Physics, Univ. of Padova, Italy              ROT13: ybergv@cq.vasa.
vg





[ Post a follow-up to this message ]



    Re: compiling socket program  
grid


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-05 12:50 PM

>>CC cl.cpp -lsocket
>
> Undefined                       first referenced
>  symbol                             in file
> gethostbyname                       cl.o  (symbol belongs to implicit
> dependency /usr/lib/libnsl.so.1)
>
>
> function socket() and connect() are fine,
> but gethostbyname() is still not linked.

If you look in the man pages of the socket() call(On Solaris,section3C
),it gives the following usage details :
cc [ flag ... ] file ... -lsocket -lnsl [ library ... ]

Also I suppose since its a Solaris box,the socket() and related
functions are available as libraries (libsocket and libnsl)and not as
system calls,though they may internally be calling the system calls
specific to the platform.
On systems like Linux,socket() and related functions are system calls in
the kernel and hence doesn't need the libraries to be specified(the
entries/stubs are present in the libc library for the system calls).

HTH





[ Post a follow-up to this message ]



    Re: compiling socket program  
SM Ryan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-23-05 10:55 PM

grid <prohit99@gmail.com> wrote:
# >>CC cl.cpp -lsocket
# >
# > Undefined                       first referenced
# >  symbol                             in file
# > gethostbyname                       cl.o  (symbol belongs to implicit
# > dependency /usr/lib/libnsl.so.1)
# >
# >
# > function socket() and connect() are fine,
# > but gethostbyname() is still not linked.
#
# If you look in the man pages of the socket() call(On Solaris,section3C
# ),it gives the following usage details :
# cc [ flag ... ] file ... -lsocket -lnsl [ library ... ]
#
# Also I suppose since its a Solaris box,the socket() and related
# functions are available as libraries (libsocket and libnsl)and not as
# system calls,though they may internally be calling the system calls
# specific to the platform.
# On systems like Linux,socket() and related functions are system calls in
# the kernel and hence doesn't need the libraries to be specified(the
# entries/stubs are present in the libc library for the system calls).

gethostbyname potentially does a DNS lookup. It can do its own
TCP or UDP socket code internally before returning. That's far
too much work to put into the kernel. On the unices I've used,
its in the libc equivalent; libc can include many things beyond
kernel calls.

Kernel calls like socket() or read() still often require a
small bit of user space code to convert the C (or Fortran or ...)
calling conventions to the particular register/stack/interrupt
code/etc used to transfer calls across the kernel-user interface.
These little bits of code are loaded from the library.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
TEMPORARILY CLOSED
BE OPENED AFTER FIRST PERIOD





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:03 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register