compilation of sockets program problem 
Author Message
 compilation of sockets program problem

Hello,
I have a problem compiling a C program that uses suckets on a Solaris 2.7
I had a problem in the beginnig with symbol 'socket' being undefined
then I fixed it issuing -lnsl -lsocket options.
now this is what my program looks like and it gives me similar errors, but
with different functions.

#include        "/home/kotlya92/lib/unp.h" // this includes all nessesery
#include        <stdio.h>                  // libraries  

int main(int argc, char **argv)
{
   int fd;
   char **pptr;
   char host[100];
   struct hostent *conct_host;
   struct sockaddr_in servaddr;
   const int HTTP_PORT = 80;

   fd = socket(AF_INET, SOCK_STREAM, 0);

   if (fd == -1) {
      printf("Error, could not create socket\n");
      exit(1);
   }

   conct_host = gethostbyname(*(argv+1));
   pptr = conct_host->h_addr_list;

   bzero(&servaddr, sizeof(servaddr));
   servaddr.sin_family = AF_INET;
   servaddr.sin_port = htons(HTTP_PORT);
   inet_pton(AF_INET, *pptr, &servaddr.sin_addr);
   connect(fd, (SA *)&servaddr, sizeof(servaddr));
   str_cli(stdin, fd);

   return 0;

Quote:
}

These are the errors I get now

libra:~/Sokets > gcc -o output -lnsl -lsocket test.c
Undefined                       first referenced
 symbol                             in file
inet_pton                           /var/tmp/ccCQg4rI.o
str_cli                             /var/tmp/ccCQg4rI.o
ld: fatal: Symbol referencing errors. No output written to output
collect2: ld returned 1 exit status
libra:~/Sokets >

Please help me.  What am I doing wrong?

--
Posted via CNET Help.com
http://www.*-*-*.com/



Tue, 15 Oct 2002 03:00:00 GMT  
 compilation of sockets program problem

in comp.lang.c:

Quote:
> Hello,
> I have a problem compiling a C program that uses suckets on a Solaris 2.7
> I had a problem in the beginnig with symbol 'socket' being undefined
> then I fixed it issuing -lnsl -lsocket options.
> now this is what my program looks like and it gives me similar errors, but
> with different functions.

Sorry, wrong newsgroup.  C itself doesn't have sockets, they are
compiler and OS specific non-standard extensions.  The functions you
are having problems with are not C language functions, they are
specific to your compiler.  We don't do extensions or compiler
specifics.  Try a Solaris or UNIX newsgroup or try the man pages for
these functions to see if it specifies what libraries they are in.

Jack Klein
--
Home: http://jackklein.home.att.net



Wed, 16 Oct 2002 03:00:00 GMT  
 compilation of sockets program problem

Quote:
>Hello,
>I have a problem compiling a C program that uses suckets on a Solaris 2.7

# prama humour
suckets for soccer ? ... or sockets for sucker ?

--
-hs- "Stove"
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkum.com/htm_cl
"Really?  When run on my machine, a printed copy of the C FAQ leaps
from the monitor and whacks me over the head.." -- Chris Mears CLC



Wed, 16 Oct 2002 03:00:00 GMT  
 compilation of sockets program problem

Quote:

> > libra:~/Sokets > gcc -o output -lnsl -lsocket test.c
> > Undefined                       first referenced
> >  symbol                             in file
> > inet_pton                           /var/tmp/ccCQg4rI.o
> > str_cli                             /var/tmp/ccCQg4rI.o
> > ld: fatal: Symbol referencing errors. No output written to output
> > collect2: ld returned 1 exit status
> > libra:~/Sokets >

> <OT hint>
> The error message is fairly clear, I think.  It is telling you that it
> doesn't know where to find the functions inet_pton() and str_cli().  It
> sounds like you'll need another #include in there...
> <OT hint>

Usually linker errors mean that you have to link another library,
not include another header.


Wed, 16 Oct 2002 03:00:00 GMT  
 compilation of sockets program problem
Dn't worry:

Try this

#include <socket.h>

or

#include <sys/socket.h>

NoKo

"Why cat?"



Wed, 16 Oct 2002 03:00:00 GMT  
 compilation of sockets program problem

Quote:

> Hello,
> I have a problem compiling a C program that uses suckets on a Solaris
> 2.7
> I had a problem in the beginnig with symbol 'socket' being undefined
> then I fixed it issuing -lnsl -lsocket options.
> now this is what my program looks like and it gives me similar errors,
> but with different functions.

> #include        "/home/kotlya92/lib/unp.h" // this includes all nessesery
> #include        <stdio.h>                  // libraries

> int main(int argc, char **argv)
> {
>    int fd;
>    char **pptr;
>    char host[100];
>    struct hostent *conct_host;
>    struct sockaddr_in servaddr;
>    const int HTTP_PORT = 80;

>    fd = socket(AF_INET, SOCK_STREAM, 0);

>    if (fd == -1) {
>       printf("Error, could not create socket\n");
>       exit(1);
>    }

>    conct_host = gethostbyname(*(argv+1));
>    pptr = conct_host->h_addr_list;

>    bzero(&servaddr, sizeof(servaddr));
>    servaddr.sin_family = AF_INET;
>    servaddr.sin_port = htons(HTTP_PORT);
>    inet_pton(AF_INET, *pptr, &servaddr.sin_addr);
>    connect(fd, (SA *)&servaddr, sizeof(servaddr));
>    str_cli(stdin, fd);

>    return 0;
> }

> These are the errors I get now

> libra:~/Sokets > gcc -o output -lnsl -lsocket test.c
> Undefined                       first referenced
>  symbol                             in file
> inet_pton                           /var/tmp/ccCQg4rI.o
> str_cli                             /var/tmp/ccCQg4rI.o
> ld: fatal: Symbol referencing errors. No output written to output
> collect2: ld returned 1 exit status
> libra:~/Sokets >

Sockets aren't a part of ANSI/ISO C.

<OT hint>
The error message is fairly clear, I think.  It is telling you that it
doesn't know where to find the functions inet_pton() and str_cli().  It
sounds like you'll need another #include in there...
<OT hint>

Cheers,
Selim
--
"There are signs that the world is speedily coming to an end: {*filter*}
and corruption are common.  Children no longer obey their parents, and
everyone is writing a book."
- from Assyrian tablet, ca. 2800 BCE



Thu, 17 Oct 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. socket server example compilation problem

2. Problem with rpcsvc/mount.h and the compilation of a program

3. Socket prog compilation

4. socket.h error in AIX c compilation

5. HELP -- Socket programming problem in Linux

6. socket programming problem (network not reachable)

7. socket programming problem (network not reachable)

8. Sockets Programming in C, a problem with bind

9. problem with socket-programming (Beginner needs help)

10. Problem when Creating SOCKET with multithread program.

11. socket programming ip problem

12. Socket Programming (How to program a timeout mechanism on a read/write call)

 

 
Powered by phpBB® Forum Software