Unix Programming - compiling socket program

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > September 2005 > compiling socket program





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author compiling socket program
ICN_OK

2005-09-22, 9:01 pm

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?

David Schwartz

2005-09-22, 9:01 pm


"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


Maurizio Loreti

2005-09-22, 9:01 pm

"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 http://www.pd.infn.it/~loreti/mlo.html
Dept. of Physics, Univ. of Padova, Italy ROT13: ybergv@cq.vasa.vg
grid

2005-09-23, 7:50 am

>>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
SM Ryan

2005-09-23, 5: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
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com