Solved

GCC/Sockets/link

Posted on 1997-10-14
10
1,236 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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