Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find out which library is home to a given object?

I'm programming in FORTRAN and C on an SGI running Irix 6.5, but this should be applicable to all Unix-like systems. How do I find which library I need to link to my program when I get an "unresolved text symbol" link error? Here's an example of what I'm seeing from the linker:

ld32: ERROR  33 Unresolved text symbol "ortho2_" -- first referenced by ./libfoo.a

Do I just have to know which libraries are required, or is there some tool or command that can help me figure this out?

like image 998
Scottie T Avatar asked Dec 02 '22 08:12

Scottie T


2 Answers

You can use the nm command to list the dynamic symbols from a shared library:

nm -D /lib/libc.so.6

and then grep for the symbol you are looking for. Omit the -D for static libraries. You can use this in a loop or with xargs to scan multiple libraries.

I usually just use google (assuming the symbol is from a publicly available library).

like image 56
Robert Gamble Avatar answered Dec 03 '22 22:12

Robert Gamble


Using nm (as in Robert Gamble's answer) is the correct answer to your question. The trick is in knowing where to look for the libraries. What does your program do? If there is a large amount of numerics going on, chances are you should be linking against math libraries (like LAPACK or BLAS) and might want to start looking there. Web searching can also be helpful - I typed "ortho2" into my favorite search engine and got this documentation that suggests it's in libfgl.a

Note that when you search you should probably omit the trailing underscore - it's usually added to the routine name by the compiler.

like image 38
Tim Whitcomb Avatar answered Dec 03 '22 22:12

Tim Whitcomb