For example, if you're doing this:
gcc -o foo foo.c
you'd want to change it to this:
gcc -o foo foo.c -lnsl
Hope that helps.
- Logan
--
"In order to be prepared to hope in what does not deceive,
we must first lose hope in everything that deceives."
Georges Bernanos
> gethostbyname() is defined in a library, but that library isn't one of
> the ones that the linker uses by default. So, you'll have to tell the
> linker to use that library using the "-lnsl" command line argument.
> For example, if you're doing this:
> gcc -o foo foo.c
> you'd want to change it to this:
> gcc -o foo foo.c -lnsl
> Hope that helps.
> - Logan
> --
> "In order to be prepared to hope in what does not deceive,
> we must first lose hope in everything that deceives."
> Georges Bernanos
NAME
gethostbyname, gethostbyname_r, gethostbyaddr,
gethostbyaddr_r, gethostent, gethostent_r, sethostent,
endhostent - get network host entry
SYNOPSIS
cc [ flag ... ] file ... -lnsl [ library ... ]
#include <netdb.h>
Doesn't the "-lnsl" indicate the necessary library?
> #
> # gethostbyname() is defined in a library, but that library isn't one of
> # the ones that the linker uses by default. So, you'll have to tell the
> # linker to use that library using the "-lnsl" command line argument.
> #
> # gcc -o foo foo.c -lnsl
> I wonder why the man pages show the necessary
> includes, but not the necessary libraries.
NAME
gethostbyname, gethostbyname_r, gethostbyaddr,
gethostbyaddr_r, gethostent, gethostent_r, sethostent,
endhostent - get network host entry
SYNOPSIS
cc [ flag ... ] file ... -lnsl [ library ... ]
#include <netdb.h>
The bit that says "-lnsl" is sort of a Big Clue.
Try a couple more:
NAME
cos - cosine function
SYNOPSIS
cc [ flag ... ] file ... -lm [ library ... ]
#include <math.h>
OK, needs -lm
NAME
kstat_open, kstat_close - initialize kernel statistics
facility
SYNOPSIS
cc[ flag ... ] file ... -lkstat [ library ...]
#include <kstat.h>
Perhaps that one might need -lkstat
And so on.
--
Tony
>I wonder why the man pages show the necessary
>includes, but not the necessary libraries.
Network Functions gethostbyname(3N)
NAME
gethostbyname, gethostbyname_r, gethostbyaddr,
gethostbyaddr_r, gethostent, gethostent_r, sethostent,
endhostent - get network host entry
SYNOPSIS
cc [ flag ... ] file ... -lnsl [ library ... ]
#include <netdb.h>
struct hostent *gethostbyname(const char *name);
struct hostent *gethostbyname_r(const char *name,
struct hostent *result, char *buffer, int buflen,
int *h_errnop);
Taken from S 7 !!! manuals (not S 9 ;-)
--
URL: http://www.fokus.gmd.de/usr/schilling ftp://ftp.fokus.gmd.de/pub/unix
1. Unix network programming; compiling source code problem
Hi! I am new to unix network programming. I am currently learning
from the book "Unix Network Programming; networking APIs: Sockets and XTI"
I followed the instruction on README. After I've compiled by command
"./configure", then try to compile the subdirectories, it gives an error
like follows:
for example,
gcc -g -02 -D_REENTRANT -Wall -c -o daytimetcpcli.o daytimetcpcli.c
In file included from daytimetcpcli.c:1:
unp.h:144:redefinition of 'struct in_pktinfo'
make: *** [daytimetcpcli.0] Error 1
I don't know why there's error and couldn't find any clue. I compiled it on
linux redhat 6.2 and the source code was downloaded from
http://www.kahola.com/start
source file: unpv12e.tar.gz
Anyone can help, thank you!
2. C code for SQL parser and reg expressions
3. A problem with compiling Unix Network Programming v1(Stevens)
4. help: GNU finger-1.37 & Sol. 2.4
5. Unix network programming; compiling source code problem
6. NIS Setup
7. Compiling "Unix Network Programming" Examples
8. web forwarding to ip address'
9. Help!! Stevens - Network programs compiling on Dec Alpha
10. difficulty compiling the Unix Network Programming libs and code
11. compiling libs from Unix Network Programming
12. Network problem, kernel compile problem
13. CC compiled .so does not work with g++ compiled main program