LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to know the library name when I already know function name (https://www.linuxquestions.org/questions/programming-9/how-to-know-the-library-name-when-i-already-know-function-name-559261/)

letuanle 06-05-2007 04:42 AM

How to know the library name when I already know function name
 
Dear all,

When I call a function in linux kernel, I want to know what library name contains that function. Please give me the solution.

For example, I want to know the name of library which contains local_bh_enable()

Thank you
Tuan Le

Centinul 06-06-2007 01:21 PM

Function: Google
Input: local_bh_enable()
Output: asm/smp.h
:)
In all seriousness, I don't know how you would try and use a function (assuming C) in C without knowing the library you are calling it from. If you don't include the library than you can't call the function.

Do you think you could explain a little more clearly what you are trying to do?

Thanks

letuanle 06-06-2007 10:08 PM

Hello Centinul,

It is easy to know which .h file need to include into my source code which calling the local_bh_enable() function. But when I compile, the error occurs (cannot link the library). I need to know the name of library which contains local_bh_enable() to pass to the command line

gcc myproject -lXX

My question is XX = ?

(XX is the name of library which contains local_bh_enable())


Thank you

Tuan Le

The_Nerd 06-07-2007 12:03 AM

Do a google search: http://www.google.com/search?client=...utf-8&oe=utf-8

kaz2100 06-07-2007 11:32 PM

Hya,

I had same question a while ago. I did not know the answer. So that, I used "nm" to see. But it did not work on Penguin. It worked with Macintosh.

Also it was not efficient at all....


Happy Penguins!

haxpor 06-08-2007 01:51 AM

The library contains in Linux is in Binary Code, so we cannot search it like the header file, I guess the only way we can do is search through the internet.

Any better ideas?

makyo 06-08-2007 06:11 AM

Hi.
Quote:

Originally Posted by kaz2100
I had same question a while ago. I did not know the answer. So that, I used "nm" to see. But it did not work on Penguin. It worked with Macintosh.

Also it was not efficient at all....

My experience is different from this. The utility nm has worked on every *nix system I have used. I don't know what Penguin is, however.

What do you mean by not efficient at all? ... cheers, makyo

kaz2100 06-08-2007 08:06 AM

Hya,

My Penguin is etch Debian. 2.6.20.11

Code:

>nm /lib/libm-2.3.6.so
nm: /lib/libm-2.3.6.so: no symbols

It is quite inefficient. Follow links to real one (/usr/lib/libm.so -> /lib/libm.so -> lib/libm-2.3.6.so) on every individual library until I find.

makyo 06-08-2007 08:53 AM

Hi.
Quote:

-D
--dynamic
Display the dynamic symbols rather than the normal symbols. This
is only meaningful for dynamic objects, such as certain types of
shared libraries.

-- excerpt from man nm
For example:
Code:

#!/bin/sh

# @(#) s1      Demonstrate nm extraction of symbols from shared libraries.

set -o nounset
echo " sh version: $BASH_VERSION"

LIB=/usr/lib/libm.a
echo
echo " Looking at $LIB:"
nm $LIB 2>/dev/null | head -10

LIB=/lib/libm-2.3.2.so
echo
echo " Looking at $LIB:"
nm -D $LIB 2>/dev/null | head -10

exit 1

Which produces:
Code:

% ./s1
 sh version: 2.05b.0(1)-release

 Looking at /usr/lib/libm.a:

k_standard.o:
        U _LIB_VERSION
        U __assert_fail
        U __copysign
        U __errno_location
00000000 T __kernel_standard
        U __rint
        U fputs
        U fwrite

 Looking at /lib/libm-2.3.2.so:
00000000 A GLIBC_2.0
00000000 A GLIBC_2.1
00000000 A GLIBC_2.2
        w _Jv_RegisterClasses
00021538 D _LIB_VERSION
        U __assert_fail
0000c380 T __clog10
00013090 T __clog10f
0001a7b0 T __clog10l
        w __cxa_finalize

If I understand your comment regarding the inefficiency of following links, that seems to be an issue of the design of library layout, rather than nm. Please clarify if I have not understood correctly ... cheers, makyo

ab1jx 06-28-2018 10:07 PM

Quote:

Originally Posted by makyo (Post 2780023)
Hi.

For example:
Code:

#!/bin/sh

# @(#) s1      Demonstrate nm extraction of symbols from shared libraries.

set -o nounset
echo " sh version: $BASH_VERSION"

LIB=/usr/lib/libm.a
echo
echo " Looking at $LIB:"
nm $LIB 2>/dev/null | head -10

LIB=/lib/libm-2.3.2.so
echo
echo " Looking at $LIB:"
nm -D $LIB 2>/dev/null | head -10

exit 1

Which produces:
Code:

% ./s1
 sh version: 2.05b.0(1)-release

 Looking at /usr/lib/libm.a:

k_standard.o:
        U _LIB_VERSION
        U __assert_fail
        U __copysign
        U __errno_location
00000000 T __kernel_standard
        U __rint
        U fputs
        U fwrite

 Looking at /lib/libm-2.3.2.so:
00000000 A GLIBC_2.0
00000000 A GLIBC_2.1
00000000 A GLIBC_2.2
        w _Jv_RegisterClasses
00021538 D _LIB_VERSION
        U __assert_fail
0000c380 T __clog10
00013090 T __clog10f
0001a7b0 T __clog10l
        w __cxa_finalize

If I understand your comment regarding the inefficiency of following links, that seems to be an issue of the design of library layout, rather than nm. Please clarify if I have not understood correctly ... cheers, makyo

I know exactly what he means though but most people don't seem to get it. In OpenBSD I had written a program that would read ldso hints then run nm on each library and shoot the output into a file in /tmp since it changed a lot anyway. Search in there with something like the mc file viewer and you find lots of treasures. In most cases it included the -l line for the library, but Linux is different, it doesn't work here. You do use it when you don't know what library to link against, or maybe you're looking at an undefined reference error from somebody else's program and trying to fix it. You can find a function name and trace it back to a library. Here, going into a directory full of libraries and doing
Code:

nm -D *.so > /tmp/dsym.txt
comes close, but no -l names, just file names.

dugan 06-29-2018 04:10 PM

Does "man local_bh_enable" give you anything?

Also, you're asking specifically about the Linux kernel's headers, and not C/C++ libraries in general, right? I'm pretty sure the answer, then, actually is RTFM. There are a lot of guides to programming against those.

ab1jx 06-29-2018 05:51 PM

No, I'm wondering about the libraries in general, not kernel-specific. Here's an example. On a Raspberry Pi I'm trying to isolate the OpenGL ES demo program called hello_triangle and set it up to build with a normal makefile, not be one of 20 or so programs that's set up for cmake. I want to try tinkering with it, making small changes, learning from it. When I run my makefile I get a slew of undefined reference errors like:
Code:

/opt/vc/lib/libEGL.so: undefined reference to `gl11_client_state_init'
/opt/vc/lib/libEGL.so: undefined reference to `glintAttribPointer'
/opt/vc/lib/libEGL.so: undefined reference to `glxx_client_GenFramebuffers'

I'm doing -lGL -lEGL -lbcm_host but -lbcm_host may be the wrong name to use. By nm, grep, etc, some of those symbols are defined in libbrcmEGL.so and libbrcmGLESv2.so among other places, but I need the -l name in order to link it.

I fired up my program (on my OpenBSD laptop) and output looks like:
Code:

search directories:  /usr/lib:/usr/X11R6/lib:/usr/local/lib

--------- -lXpm.9.0    /usr/X11R6/lib/libXpm.so.9.0 -----------
t AllocColor
t CreateColors
t CreateXImage
t FreeColors
t GetImagePixels1
t OpenArray
t OpenBuffer
t OpenReadFile
t ParseComment
t PutImagePixels

T fetch_2d_texel_rgba_dxt5
T tx_compress_dxtn
t writedxt5encodedalphablock
t writedxt5encodedalphablock
--------- -lxcb-dri2.1.1        /usr/X11R6/lib/libxcb-dri2.so.1.1 --------- - -----------
a _DYNAMIC
a _GLOBAL_OFFSET_TABLE_
d __dso_handle
d __guard_local
t __i686.get_pc_thunk.bx
T _fini
T _init
t atexit
T xcb_dri2_attach_format_end
T xcb_dri2_attach_format_next
T xcb_dri2_authenticate
T xcb_dri2_authenticate_reply
T xcb_dri2_authenticate_unchecked
T xcb_dri2_connect
T xcb_dri2_connect_alignment_pad

It lists the -l name, the file name and path, and some subset of the symbols. Not all are useful. But a BSD nm has different command-line options, it works differently. There's no quick translation.

No, man local_bh_enable doesn't do anything. And this isn't for headers, -I/opt/vc/include seems to cover those well enough. The Broadcom libraries are in -L/opt/vc/lib but I need names.

dugan 06-29-2018 06:07 PM

Quote:

Originally Posted by ab1jx (Post 5873698)
On a Raspberry Pi I'm trying to isolate the OpenGL ES demo program called hello_triangle...

This one?

https://github.com/danginsburg/openg...Hello_Triangle

Just get that information from the CMake files.

The surest way is to actually do a CMake build and just look at which gcc flags are being applied.

The actual library names CMake looks for are in the sources for the CMake modules in /usr/share/cmake/Modules.

dugan 06-29-2018 06:28 PM

Quote:

/opt/vc/lib/libEGL.so: undefined reference to `gl11_client_state_init'
That doesn't look right at all. Are you sure you did everything right building that, since you obviously built it yourself?

Code:

ldd /opt/vc/lib/libEGL.so
Anything "NOT FOUND"?

dugan 06-29-2018 06:31 PM

Quote:

By nm, grep, etc, some of those symbols are defined in libbrcmEGL.so and libbrcmGLESv2.so among other places, but I need the -l name in order to link it.
Just drop the "lib" prefix.

These would be "-lbrcmEGL" and "-lbrcmGLESv2"

If that's all you wanted to know, mark the thread as "solved".


All times are GMT -5. The time now is 11:29 PM.