Solved

GCC/Sockets/link

Posted on 1997-10-14
10
1,248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 84

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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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 260 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

630 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