Solved

GCC/Sockets/link

Posted on 1997-10-14
10
1,182 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 84

Expert Comment

by:ozo
Comment Utility
try
cc -lsocket
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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
Comment Utility
SunOS 5.5.1
GCC 2.7.2.1
Actually, GCC -lsocket works for all entries, except "inet_addr"...

0
 
LVL 1

Author Comment

by:trof
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:trof
Comment Utility
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
Comment Utility
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
Comment Utility
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 260 total points
Comment Utility


Actually, you need

-lsocket -lnsl

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

-Tony


0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 51
Whole sheet autoscrub still needed 19 44
maxBlock challenge 30 99
Line meaning 9 75
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now