From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Frost To: Shicheng Cc: help-gcc@gnu.org Subject: Re: socket: Undefined Date: Fri, 01 Oct 1999 00:00:00 -0000 Message-ID: References: <7s5rcm$q40$1@nnrp1.deja.com> X-SW-Source: 1999-q3/msg00703.html Message-ID: <19991001000000.ML1JBJQtqHwuOv5sO-Yb9NMGonr1YeDQmsWm0SmtNPM@z> 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 #include 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 , 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. >