How to find what library a symbol is defined in.

I have sometimes been faced with problems when compiling open source
packages that a link step will fail with "undefined symbol" errors.
This is usually a case of a package that compiles as-is under some
other UNIX but fails on Solaris because of packaging differences. A
good example would be a symbol like "gethostname". On Solaris you need
to specify "-lnsl" on the link command the get this resolved but
apparently you don't on other unices.

My question is this. Given a particular symbol name, is there a way to
scan or determine somehow which library, if any, on the system defines
the symbol?

TIA

Jim Lane
0
Jim
11/22/2007 1:46:40 PM
comp.unix.solaris 25985 articles. 1 followers. Post Follow

6 Replies
1616 Views

Similar Articles

[PageSpeed] 54

Jim.Lane@cibc.com writes:

> My question is this. Given a particular symbol name, is there a way to
> scan or determine somehow which library, if any, on the system defines
> the symbol?

$ /usr/ccs/bin/nm -Ap /usr/lib/* 2>/dev/null | grep ' gethostbyname$' | grep -v ' U '
/usr/lib/libnsl.a[gethostent.o]: 0000000000 T gethostbyname
/usr/lib/libnsl.so: 0000221468 T gethostbyname
/usr/lib/libnsl.so.1: 0000221468 T gethostbyname
/usr/lib/libxnet.so: 0000000000 T gethostbyname
/usr/lib/libxnet.so.1: 0000000000 T gethostbyname

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
0
Paul
11/22/2007 3:47:49 PM
In <c02dbf2c-1e17-4dc8-b0fe-dd77464da7a1@t47g2000hsc.googlegroups.com> Jim.Lane@cibc.com writes:

>I have sometimes been faced with problems when compiling open source
>packages that a link step will fail with "undefined symbol" errors.
>This is usually a case of a package that compiles as-is under some
>other UNIX but fails on Solaris because of packaging differences. A
>good example would be a symbol like "gethostname". On Solaris you need
>to specify "-lnsl" on the link command the get this resolved but
>apparently you don't on other unices.

>My question is this. Given a particular symbol name, is there a way to
>scan or determine somehow which library, if any, on the system defines
>the symbol?

I usually look at the man page.  It lists both the library names
and the include files needed by the function.  Here's an example:

  NAME
       getsockopt, setsockopt - get and set options on sockets
  
  SYNOPSIS
       cc [ flag ... ] file ... -lsocket -lnsl [ library ... ]
       #include <sys/types.h>
       #include <sys/socket.h>

I don't know if there's a database for this purpose.

-- 
-Gary Mills-    -Unix Support-    -U of M Academic Computing and Networking-
0
Gary
11/22/2007 4:01:50 PM
On Nov 22, 5:46 am, Jim.L...@cibc.com wrote:
> I have sometimes been faced with problems when compiling open source
> packages that a link step will fail with "undefined symbol" errors.
> This is usually a case of a package that compiles as-is under some
> other UNIX but fails on Solaris because of packaging differences. A
> good example would be a symbol like "gethostname". On Solaris you need
> to specify "-lnsl" on the link command the get this resolved but
> apparently you don't on other unices.
>
> My question is this. Given a particular symbol name, is there a way to
> scan or determine somehow which library, if any, on the system defines
> the symbol?

Just use "nm" and pipe to awk scanning for ABS but not LOCL or some
type of
shell scripting to isolate what you are looking for. nm being the key.
Maybe theres a more clever way but  its not something you do a lot so
I just scribble something up on the fly when needed.
0
gerryt
11/22/2007 4:25:34 PM
On Nov 22, 10:47 am, Paul Pluzhnikov <ppluzhnikov-...@charter.net>
wrote:
> Jim.L...@cibc.com writes:
> > My question is this. Given a particular symbol name, is there a way to
> > scan or determine somehow which library, if any, on the system defines
> > the symbol?
>
> $ /usr/ccs/bin/nm -Ap /usr/lib/* 2>/dev/null | grep ' gethostbyname$' | grep -v ' U '
> /usr/lib/libnsl.a[gethostent.o]: 0000000000 T gethostbyname
> /usr/lib/libnsl.so: 0000221468 T gethostbyname
> /usr/lib/libnsl.so.1: 0000221468 T gethostbyname
> /usr/lib/libxnet.so: 0000000000 T gethostbyname
> /usr/lib/libxnet.so.1: 0000000000 T gethostbyname
>
> Cheers,
> --
> In order to understand recursion you must first understand recursion.
> Remove /-nsp/ for email.

Interesting. How am I to interpret the result in your example above?
It appears as if gethostbyname is defined in 2 places, libnsl and
libxnet. Which of the 2 should one use? Or does it matter?

-Jim
0
Jim
11/22/2007 6:08:24 PM
On Nov 22, 11:01 am, Gary Mills <mi...@cc.umanitoba.ca> wrote:
> In <c02dbf2c-1e17-4dc8-b0fe-dd77464da...@t47g2000hsc.googlegroups.com> Jim.L...@cibc.com writes:
> >I have sometimes been faced with problems when compiling open source
> >packages that a link step will fail with "undefined symbol" errors.
> >This is usually a case of a package that compiles as-is under some
> >other UNIX but fails on Solaris because of packaging differences. A
> >good example would be a symbol like "gethostname". On Solaris you need
> >to specify "-lnsl" on the link command the get this resolved but
> >apparently you don't on other unices.
> >My question is this. Given a particular symbol name, is there a way to
> >scan or determine somehow which library, if any, on the system defines
> >the symbol?
>
> I usually look at the man page.  It lists both the library names
> and the include files needed by the function.  Here's an example:
>
>   NAME
>        getsockopt, setsockopt - get and set options on sockets
>
>   SYNOPSIS
>        cc [ flag ... ] file ... -lsocket -lnsl [ library ... ]
>        #include <sys/types.h>
>        #include <sys/socket.h>
>
> I don't know if there's a database for this purpose.
>
> --
> -Gary Mills-    -Unix Support-    -U of M Academic Computing and Networking-

Well, OK. I'm not sure how general a solution this is. Using a
solution
posted by another user I've discovered the location of another symbol
I'd been having trouble with:

 # /usr/ccs/bin/nm -Ap /usr/lib/* 2>/dev/null | grep ' Malloc$' | grep
-v ' U '
/usr/lib/libmeta.so: 0000199160 T Malloc
/usr/lib/libmeta.so.1: 0000199160 T Malloc

However there seems not to be a man page for Malloc.

-Jim
0
Jim
11/22/2007 6:13:29 PM
Jim.Lane@cibc.com writes:

> On Nov 22, 10:47 am, Paul Pluzhnikov <ppluzhnikov-...@charter.net>
> wrote:
>> Jim.L...@cibc.com writes:
>> > My question is this. Given a particular symbol name, is there a way to
>> > scan or determine somehow which library...

>> /usr/lib/libnsl.a[gethostent.o]: 0000000000 T gethostbyname
>> /usr/lib/libnsl.so: 0000221468 T gethostbyname
>> /usr/lib/libxnet.so: 0000000000 T gethostbyname
>
> Interesting. How am I to interpret the result in your example above?

Exactly as the answer to your question: these are the 3 libraries
that define the symbol that you are looking for.

> It appears as if gethostbyname is defined in 2 places, libnsl and
> libxnet. Which of the 2 should one use? Or does it matter?

That's a different question from the one you originally asked.
You'll have to check what other symbols the libraries define,
use man pages for these other functions, or google a bit, or guess
and try either.

You could also run 'elfdump' on the libraries, and learn more
about them. On my Solaris8 box, I get:

$ elfdump -d /usr/lib/libxnet.so

Dynamic Section:  .dynamic
     index  tag               value
       [0]  SONAME           0x4a9             libxnet.so.1
       [1]  FILTER           0x4b6             libsocket.so.1:libnsl.so.1:libc.so.1
       [2]  HASH             0x74              
       [3]  STRTAB           0xc84             
       [4]  STRSZ            0x4db             
       [5]  SYMTAB           0x4b4             
       [6]  SYMENT           0x10              
       [7]  CHECKSUM         0xf563            
       [8]  VERDEF           0x1160            
       [9]  VERDEFNUM        0x3               
      [10]  FLAGS_1          0x10              [ LOADFILTER ]


So libxnet.so is a filter over libsocket and libnsl.
You can learn more about filter libraries here:

  http://docs.sun.com/app/docs/doc/816-0559/6m71o2afb?a=view#chapter4

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
0
Paul
11/22/2007 9:18:48 PM
Reply:

Similar Artilces:

Where to find symbols in libraries?
I have a basic question about libraries. I am trying to build konqueror embedded, and if I use only the libraries on my embedded system, the build fails because it cannot find inet_pton. The problem is described here: <http://lists.kde.org/?l=konq-e&m=107478562601204&w=2> . The solution is to set up your libs so that configure can find the lib with inet_pton.... So... How do I find out which lib I need? nm returns a whole pile of inet_pton symbols, but I have no idea how to read it. Could someone help me out? Thanks, --Yan CptDondo <yan@NsOeSiPnAeMr.com> wrote ...

Process Scehduling in Unix version Sun Solaris (I know this is the linux group but I couldnt find a sun solaris one)
I just needed to find out how processes are scheduled in Sun's solaris and an outline of the scheduling algorithm - I've looked on the web without anyluck - couldnt find anything specific. "Amerz" <amerdeep@gmail.com> writes: > I just needed to find out how processes are scheduled in Sun's solaris > and an outline of the scheduling algorithm - I've looked on the web > without anyluck - couldnt find anything specific. > Assuming oyu mean threads too, then you didnt look very hard - first search gives this: http://www.google.de/search?q=solaris+ke...

How to define a define that defines some defines ?
Hi all, I have the following: /*--- SNIP ---*/ typedef struct Argument_s { char *address; int type; int length; } ARGUMENT; #define Function(F) int F( int ArgCount, ARGUMENT ArgVector[] ) #define First ArgVector[0] #define First_A First.address #define First_T First.type #define First_L First.length #define Second ArgVector[1] #define Second_A Second.address #define Second_T Second.type #define Second_L Second.length #define Third ArgVector[2] #define Third_A Third.address #define Third_T Third.type #define Third_L Third.length ...

Multiply defined symbols in wx libraries
Hi, I am using wxMSW 2.6.1, Win XP. When building my project, I receive the message wxbase26d.lib(log.obj) : error LNK2005: "void __cdecl wxLogDebug(char const *,...)" (?wxLogDebug@@YAXPBDZZ) already defined in wxmsw26_adv.lib(grid.obj) which sounds like a wx library multiple definition. How to cure it? Thanks Janos --------------------------------------------------------------------- To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org For additional commands, e-mail: wx-users-help@lists.wxwidgets.org Sorry for the false alarm. Somehow I used...

Solaris/Unix commands to find out memory leaks?
The following is an excerpt from one of my older posts which was never answered: -------- how about the reliability of the output given by 'pmap <pid> | grep heap'. Can we consider it as a leak, if the heap size keeps growing? Btw, can there be any other cause for memory leaks? If yes, the above way may not be complete, I suppose. Could somebody clarify? Overall, it is ambiguous about what Simple Solaris commands to use to find out whether there are leaks are not(rather than using tools)? Is there any descriptive paper providing complete information on it? -------- Can anybody...

control over symbol visibility in 3rd party library on Solaris
Hello, We have two 3rd party libraries dynamically linked to our application. Both libraries have functions with identical signatrures. (To satisfy someones's curiosity these are odbc and DB2 CLI libraries with the whole set of SQLXXX() functions. Since runtime loader maintains a single name space for all symbols, the first definition visible to the runtime loader is used by default. Is there any way to control symbol visibility on Solaris 9 and Solaris 10 platforms? We use Sun C++ 5.5 and Solaris Link Editors: 5.9-1.375 on Solaris 9 and Sun C++ 5.8 Patch 121017-19 and Solar...

how can i find the patch level of Solaris shared C++ libraries?
how can i find the patch level of Solaris shared C++ libraries? linux_bp <rishabh.garg@gmail.com> wrote: > how can i find the patch level of Solaris shared C++ libraries? showrev -p |grep SUNWlibC - or - what /usr/lib/libC.so.5 and search for a string resembling a patch-ID. -- Daniel Thanks for the help. I have further queries: are Solaris shared C++ libraries patch are part of solaris kernel patches or they need to be installed seperately? Also If i compiled my binaries on machine with older C++ shared libraries, then would my application run properly on the machine with dif...

What to do with a linker warning about a public symbol from the STL library defined in two modules?
Hello All, I'm getting the following linker warning: (I'm using Borland C++ Builder 6) [Linker Warning] Public symbol '_STL::basic_ostream<char, _STL::char_traits<char> >& _STL::operator << (_STL::basic_ostream<char, _STL::char_traits<char> >&, const signed char *)' defined in both module C:\ROSIEN\MONTIUM\SIMULATOR\MONTIUMSIMUTILITY.OBJ and C:\ROSIEN\HIGH2\BASICSIMULATOR.OBJ I don't understand why this is happening. Obviously this is not a symbol I have defined, it is an STL function. I know I am including <iostream> and oth...

Help: Define a function for association list for finding a symbol's source and destination
How to define a function taht takes an A-list and return the list of elements that appear both as the source and destination in the A-list? For example: (source-dest '((a . b) (b . c) (c .a))) Pls help garynkill wrote: > How to define a function taht takes an A-list and return the list of > elements that appear both as the source and destination in the A-list? > > For example: > (source-dest '((a . b) (b . c) (c .a))) > Pls help Homework problem? -- A. Kanawati NO.antounk.SPAM@comcast.net yes...how to go about solving it....i can't seem to be able to c...

Solaris 10 x86 : shared library mismatched symbols after patch 124923-03 Mar 2007
Hello all, I am facing a frustrating problem with my Ultra 20 M2 workstation: Summary of problem: 1) -----------> After I installed patch: 124923-03 Mar 2007, shared library utilities (eg., ld, ldd, etc.) fail to find certain symbols in shared libraries: m[pts/9]:src% ld ld.so.1: ld: fatal: relocation error: file /lib/libld.so.4: symbol dbg_desc: referenced symbol not found ld.so.1: ld: fatal: relocation error: file /usr/ccs/bin/ld: symbol ld32_main: referenced symbol not found Killed -- m[pts/9]:src% ldd /usr/bin/ls ld.so.1: ldd: fatal: relocation error: file /usr/bin/ldd: symbo...

Q: can't find C++ symbols if gcc linking with Sun C++ library
Dear C++ guru, I need to compile C++ server which used a lot of GNU G++ specific codes AND one Sun C++ library g++ -c a_i.cc i=1,...n then g++ a_i.o ... -lSUNLIB_other -lGNULIB_other(s) -o exe Undefined symbol: Cl::Cl(void) Cl::set(int) Cl::~Cl(void) .... So, seems that Sun C++ and G++ differently resolved classes ..... Is it true? Or there are some options here? What can I do? I can't recompile SUNLIB_other under g++, can't GNULIB_other under SUN CC. Best regards, Albert. P.S.: Could you also send your answers to brecht_11@yahoo.com too Albert wrot...

How to find name of shared library within that library
How can I find the name of a .so file (shared library) from code within the file? Here's what I am trying to do: I am writing a shared library to be used by other developers. I would like to be able to checksum the library at startup, to make sure it's not corrupted. (This is a FIPS 140-2 requirement.) Since the function _init() in the library is called automatically whenever an application loads the library, that would seem to be the place to put the checksumming code. But I don't know how to find the full path to the .so file, which I need in order to read and ch...

Symbole referencing errors: symbol is defined multiple times
Hi Bhooshan and all, I�m having a large Vc++-project which contains several C files. My task is to convert these exisiting code to run on a TI C62x. After having done the necessary modi-fications I have problems with the TI Code Composer v3 linker. When I compile the project,I get the following linking error: [Linking...] "C:\CCStudioEval\C6000\cgtools\bin\cl6x" -@"Debug.lkf" <Linking> >> error: symbol _errortext is defined multiple times: Likewise im getting some 450 symbol referencing errors.I don`t understand why the symbols are defined multiple times I...

Shared library compiled on Solaris, incompatible with Solaris 9?
Hi, I am having a problem with a shared library (.so) that was compiled on Solaris 8 with gcc (2.95?). When this shared library was built, it was linked with a function from another static library (.a). I am running Solaris 9 (SPARC) here, and the initial problem I ran into was that when I first got the .so from the vendor, the function that came from the static library was missing ("ldd" would not display it). I've been working with one of the vendor's developers, and he sent me the souce for the shared lib. I already had a copy of the .a file, and I used CC from Sun St...

Web resources about - How to find what library a symbol is defined in. - comp.unix.solaris

Library - Wikipedia, the free encyclopedia
A library is an organized collection of sources of information and similar resources, made accessible to a defined community for reference or ...

Library - Wikipedia, the free encyclopedia
A library is an organized collection of sources of information and similar resources, made accessible to a defined community for reference or ...

Library - Wikipedia, the free encyclopedia
A library's collection can include books , periodicals , newspapers , manuscripts , films , maps , prints , documents , microform , CDs , cassettes ...

$27m Toowoomba library delayed by fire issues
Toowoomba Regional Council's new $27 million library has been delayed after inspections revealed it was not fire compliant, shortly before it ...

Food bank plan for Canberra's overdue library fees
... fines for overdue books in exchange for food donations to OzHarvest. Minister for Municipal Services Meegan Fitzharris at the Gungahlin Library. ...

Netflix won't stop Aussies sneaking into its US library
Netflix's geo-blocking crackdown is doomed to fail, assuming the streaming giant even expects it to succeed.

Supporters helping Gander library stock shelves for Syrian refugees
Employees with the Gander Public Library are doing their best to make sure the shelves are stocked for the five refugee families who are coming ...

Feature Request: iCloud Photo Library needs a purge downloads button à la Google Photos
I’ve been all in on iCloud Photo Library since Apple replaced iPhoto with the new Photos app on the Mac last year and I haven’t looked back since. ...

Law School Turns Library Back Office Into Doc-Review Dungeon
Which law school is turning part of its library into a "legal delivery center"?

Carry your entire ePub library in your pocket with Hyphen
... eBooks, Magazines, Newspapers & Textbooks Goodreads Book Recommendations and Reviews for great Books and eBooks Carry your entire ePub library ...

Resources last updated: 2/3/2016 9:02:37 AM