public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Stephen Frost <sfrost@ns.snowman.net>
To: Shicheng <S.Tian@shu.ac.uk>
Cc: help-gcc@gnu.org
Subject: Re: socket: Undefined
Date: Mon, 20 Sep 1999 11:05:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.05.9909201809370.27369-100000@ns.snowman.net> (raw)
In-Reply-To: <7s5rcm$q40$1@nnrp1.deja.com>

	Your problem is a linking problem.  You are not linking in the
appropriate libraries.  If you do a 'man socket' you will see that
the first line in the SYNOPSIS is the cc line, which tells you what
libraries you need to link in in order to use the 'socket' function.

SYNOPSIS
     cc  [ flag ... ] file ... -lsocket -lnsl [ library ... ]
     #include <sys/types.h>
     #include <sys/socket.h>

     int socket(int domain, int type, int protocol);

	As you can see, in this case you would need to use 'socket'
and 'nsl'.  So your gcc command would look something like:

gcc -lsocket -lnsl *.c

	You may wish to check the other functions you use to see if
they have other libraries that need to be linked in.

		Stephen

On Mon, 20 Sep 1999, Shicheng wrote:

> I work on SunOS 5.6 platform from a networked NT machine via telnet; and
> I would like to obtain some advice on using the gcc compiler. Under my
> working dir, there are five files: connectsock.c,
> connecttcp.c, connectudp.c, errexit.c and tcpdaytime.c; after issuing
> the commend:
> 
> gcc *.c
> 
> however, I got the following errors:
> 
> "[60]% gcc *.c
> Undefined                      first referenced
> symbol                            in file
> socket                              /var/tmp/cc0heQO31.o
> getprotobyname                      /var/tmp/cc0heQO31.o
> gethostbyname                      /var/tmp/cc0heQO31.o
> getservbyname                      /var/tmp/cc0heQO31.o
> inet_addr                          /var/tmp/cc0heQO31.o
> connect                            /var/tmp/cc0heQO31.o
> ld: fatal: Symbol referencing errors. No output written to a.out"
> 
> In the file connectsock.c, I do include the follwing paths:
> 
> #include "/usr/include/sys/types.h"
> #include "/usr/include/sys/socket.h"
> 
> #include "/usr/include/netinet/in.h"
> #include "/usr/include/netdb.h"
> 
> I even checked all the required files are there under the include dir! I
> had the same errors when using "cc" as well!
> 
> BTW, when trying another simple program which just makes use
> of the #include <stdio.h>, there is no problem/errors at all!
> 
> Thanks for sending me some advice on how to solve this problem.
> 
> Shicheng
> 
> 
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
> 

WARNING: multiple messages have this Message-ID
From: Stephen Frost <sfrost@ns.snowman.net>
To: Shicheng <S.Tian@shu.ac.uk>
Cc: help-gcc@gnu.org
Subject: Re: socket: Undefined
Date: Thu, 30 Sep 1999 23:56:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.05.9909201809370.27369-100000@ns.snowman.net> (raw)
Message-ID: <19990930235600.PndvHo9s4Xn1kTK08u_PKyGINClkLeasV83Zo7Fehy4@z> (raw)
In-Reply-To: <7s5rcm$q40$1@nnrp1.deja.com>

	Your problem is a linking problem.  You are not linking in the
appropriate libraries.  If you do a 'man socket' you will see that
the first line in the SYNOPSIS is the cc line, which tells you what
libraries you need to link in in order to use the 'socket' function.

SYNOPSIS
     cc  [ flag ... ] file ... -lsocket -lnsl [ library ... ]
     #include <sys/types.h>
     #include <sys/socket.h>

     int socket(int domain, int type, int protocol);

	As you can see, in this case you would need to use 'socket'
and 'nsl'.  So your gcc command would look something like:

gcc -lsocket -lnsl *.c

	You may wish to check the other functions you use to see if
they have other libraries that need to be linked in.

		Stephen

On Mon, 20 Sep 1999, Shicheng wrote:

> I work on SunOS 5.6 platform from a networked NT machine via telnet; and
> I would like to obtain some advice on using the gcc compiler. Under my
> working dir, there are five files: connectsock.c,
> connecttcp.c, connectudp.c, errexit.c and tcpdaytime.c; after issuing
> the commend:
> 
> gcc *.c
> 
> however, I got the following errors:
> 
> "[60]% gcc *.c
> Undefined                      first referenced
> symbol                            in file
> socket                              /var/tmp/cc0heQO31.o
> getprotobyname                      /var/tmp/cc0heQO31.o
> gethostbyname                      /var/tmp/cc0heQO31.o
> getservbyname                      /var/tmp/cc0heQO31.o
> inet_addr                          /var/tmp/cc0heQO31.o
> connect                            /var/tmp/cc0heQO31.o
> ld: fatal: Symbol referencing errors. No output written to a.out"
> 
> In the file connectsock.c, I do include the follwing paths:
> 
> #include "/usr/include/sys/types.h"
> #include "/usr/include/sys/socket.h"
> 
> #include "/usr/include/netinet/in.h"
> #include "/usr/include/netdb.h"
> 
> I even checked all the required files are there under the include dir! I
> had the same errors when using "cc" as well!
> 
> BTW, when trying another simple program which just makes use
> of the #include <stdio.h>, there is no problem/errors at all!
> 
> Thanks for sending me some advice on how to solve this problem.
> 
> Shicheng
> 
> 
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
> 

WARNING: multiple messages have this Message-ID
From: Stephen Frost <sfrost@ns.snowman.net>
To: Shicheng <S.Tian@shu.ac.uk>
Cc: help-gcc@gnu.org
Subject: Re: socket: Undefined
Date: Fri, 01 Oct 1999 00:00:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.05.9909201809370.27369-100000@ns.snowman.net> (raw)
Message-ID: <19991001000000.ML1JBJQtqHwuOv5sO-Yb9NMGonr1YeDQmsWm0SmtNPM@z> (raw)
In-Reply-To: <7s5rcm$q40$1@nnrp1.deja.com>

	Your problem is a linking problem.  You are not linking in the
appropriate libraries.  If you do a 'man socket' you will see that
the first line in the SYNOPSIS is the cc line, which tells you what
libraries you need to link in in order to use the 'socket' function.

SYNOPSIS
     cc  [ flag ... ] file ... -lsocket -lnsl [ library ... ]
     #include <sys/types.h>
     #include <sys/socket.h>

     int socket(int domain, int type, int protocol);

	As you can see, in this case you would need to use 'socket'
and 'nsl'.  So your gcc command would look something like:

gcc -lsocket -lnsl *.c

	You may wish to check the other functions you use to see if
they have other libraries that need to be linked in.

		Stephen

On Mon, 20 Sep 1999, Shicheng wrote:

> I work on SunOS 5.6 platform from a networked NT machine via telnet; and
> I would like to obtain some advice on using the gcc compiler. Under my
> working dir, there are five files: connectsock.c,
> connecttcp.c, connectudp.c, errexit.c and tcpdaytime.c; after issuing
> the commend:
> 
> gcc *.c
> 
> however, I got the following errors:
> 
> "[60]% gcc *.c
> Undefined                      first referenced
> symbol                            in file
> socket                              /var/tmp/cc0heQO31.o
> getprotobyname                      /var/tmp/cc0heQO31.o
> gethostbyname                      /var/tmp/cc0heQO31.o
> getservbyname                      /var/tmp/cc0heQO31.o
> inet_addr                          /var/tmp/cc0heQO31.o
> connect                            /var/tmp/cc0heQO31.o
> ld: fatal: Symbol referencing errors. No output written to a.out"
> 
> In the file connectsock.c, I do include the follwing paths:
> 
> #include "/usr/include/sys/types.h"
> #include "/usr/include/sys/socket.h"
> 
> #include "/usr/include/netinet/in.h"
> #include "/usr/include/netdb.h"
> 
> I even checked all the required files are there under the include dir! I
> had the same errors when using "cc" as well!
> 
> BTW, when trying another simple program which just makes use
> of the #include <stdio.h>, there is no problem/errors at all!
> 
> Thanks for sending me some advice on how to solve this problem.
> 
> Shicheng
> 
> 
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
> 

  parent reply	other threads:[~1999-09-20 11:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-20 10:57 Shicheng
1999-09-20 11:04 ` Peter A. Friend
1999-09-30 23:56   ` Peter A. Friend
1999-10-01  0:00   ` Peter A. Friend
1999-09-20 11:05 ` Stephen Frost [this message]
1999-09-30 23:56   ` Stephen Frost
1999-10-01  0:00   ` Stephen Frost
1999-09-30 23:56 ` Shicheng
1999-10-01  0:00 ` Shicheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.05.9909201809370.27369-100000@ns.snowman.net \
    --to=sfrost@ns.snowman.net \
    --cc=S.Tian@shu.ac.uk \
    --cc=help-gcc@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).