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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cc -lsocket
Which OS do you have?
For most UNIXs they should be in  libc.a and/or libc.so.
trofAuthor Commented:
SunOS 5.5.1
Actually, GCC -lsocket works for all entries, except "inet_addr"...

Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

trofAuthor Commented:
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 ?
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
trofAuthor Commented:
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 ?
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 ;-)

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

Actually, you need

-lsocket -lnsl

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



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.