Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

GCC/Sockets/link

Posted on 1997-10-14
10
Medium Priority
?
1,271 Views
Last Modified: 2013-12-26
I wrote small CGI (C language), and it using sockets. Source code compiles without any problem, but during linking I've got messages

Undefined                       first referenced
 symbol                             in file
socket                              /var/tmp/cca000Ms1.o
inet_addr                           /var/tmp/cca000Ms1.o
sendto                              /var/tmp/cca000Ms1.o
shutdown                            /var/tmp/cca000Ms1.o  

So, I guess, GCC does not see some libraries
Does enybody know, which flags should I use, to include this library into linking process ?
Thanks in advance
Alexey Trofimov
0
Comment
Question by:trof
10 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 1295284
try
cc -lsocket
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1295285
Which OS do you have?
For most UNIXs they should be in  libc.a and/or libc.so.
0
 
LVL 1

Author Comment

by:trof
ID: 1295286
SunOS 5.5.1
GCC 2.7.2.1
Actually, GCC -lsocket works for all entries, except "inet_addr"...

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:trof
ID: 1295287
oooppss, sorry, maybe, it's another error...

Undefined                       first referenced
 symbol                             in file
inet_addr                           /var/tmp/cca0006H1.o  (symbol belongs to imp
licit dependency /usr/lib/libnsl.so.1)
   
So, what I suppose to do now ?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1295288
try to find the library which contains the requested symbol, add this library to your link command.

#! /bin/csh -f -b
foreach l (/usr/lib/lib*.so.*)
echo ------------- $l
nm -gop $l | grep inet_addr
end
0
 
LVL 1

Author Comment

by:trof
ID: 1295289
Thanks, I guess, how it suppose to work, but

------------- /usr/lib/libC.so.3
nm: Command not found

Ok, let's say, I found 5-10 files, include "inet_addr". Some of them just call this function, right ? How I know witch one does contain real code of this function(not just call of it ) ? And if I know exactly name of proper file, what should I type in command line of GCC ?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1295290
no nm? Sounds strange. Do you need a path to it?

Anyway, nm reports the referenced and defined symbols in a library. Defined (text) symbols are marked  T  or  t, undefined (referenced) symbols are marked  U. This is how you can find the right library.

Of cause my shell example could be more sophisticated to get only the desired names, but this also should report what you need.

If you have no  nm,  strings  (without options) could be used, but it does not give you a hint if its defined or referenced.

Should I've marked it as answer ;-)

0
 
LVL 4

Expert Comment

by:jos010697
ID: 1295291
I'm astonished ... the entire socket stuff is supposed to
be part of libc.a. Are you sure you're linking in the
correct libc.a, i.e. /usr/lib/libc.a (or equivalent).

Could you show the actual command line you're using for
the linkage of this all?

kind regards,

Jos aka jos@and.nl
0
 
LVL 4

Accepted Solution

by:
rembo earned 1040 total points
ID: 1295292


Actually, you need

-lsocket -lnsl

on your link line.  That's the SVR4 approach :)

-Tony


0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1295293
Unfortunately I'm off from Solaris (SunOS 5.x), that's why I suggested to search for the symbols in the existing libs.

As far as I could remember  -lnsl  is the the approach, thanks rembo. As closer as one get to SVR4  -lsocket  is it too :)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question