LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-05-2007, 04:42 AM   #1
letuanle
LQ Newbie
 
Registered: Jul 2006
Posts: 2

Rep: Reputation: 0
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

Last edited by letuanle; 06-05-2007 at 04:52 AM.
 
Old 06-06-2007, 01:21 PM   #2
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
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
 
Old 06-06-2007, 10:08 PM   #3
letuanle
LQ Newbie
 
Registered: Jul 2006
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
Old 06-07-2007, 12:03 AM   #4
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Do a google search: http://www.google.com/search?client=...utf-8&oe=utf-8
 
Old 06-07-2007, 11:32 PM   #5
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,833

Rep: Reputation: 108Reputation: 108
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!
 
Old 06-08-2007, 01:51 AM   #6
haxpor
Member
 
Registered: Dec 2006
Distribution: Ubuntu 20.04
Posts: 87

Rep: Reputation: 15
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?
 
Old 06-08-2007, 06:11 AM   #7
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
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
 
Old 06-08-2007, 08:06 AM   #8
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy .. bullseye bookworm
Posts: 1,833

Rep: Reputation: 108Reputation: 108
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.
 
Old 06-08-2007, 08:53 AM   #9
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
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
 
Old 06-28-2018, 10:07 PM   #10
ab1jx
Member
 
Registered: Feb 2017
Posts: 88

Rep: Reputation: Disabled
Quote:
Originally Posted by makyo View Post
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.
 
Old 06-29-2018, 04:10 PM   #11
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
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.

Last edited by dugan; 06-29-2018 at 04:28 PM.
 
Old 06-29-2018, 05:51 PM   #12
ab1jx
Member
 
Registered: Feb 2017
Posts: 88

Rep: Reputation: Disabled
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.
 
Old 06-29-2018, 06:07 PM   #13
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by ab1jx View Post
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.

Last edited by dugan; 06-29-2018 at 06:18 PM.
 
Old 06-29-2018, 06:28 PM   #14
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
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"?

Last edited by dugan; 06-29-2018 at 06:29 PM.
 
Old 06-29-2018, 06:31 PM   #15
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
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".

Last edited by dugan; 06-29-2018 at 06:33 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
list library function of a shared library .so powah Linux - General 7 10-25-2011 04:47 AM
gets library function in C reddazz Programming 3 03-27-2005 02:04 AM
Source Function Library dadepfan Linux - General 2 08-22-2004 11:06 PM
what is the function library of the basic graphics library in rethat9.0? zerwolve Red Hat 0 04-29-2004 09:18 PM
C# using DotGNU, how do I use a library function? exodist Programming 3 02-22-2004 09:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration