C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-17-2007, 08:39 PM   #1
Devil™
 
Join Date: Oct 2007
Location: IIT-Kharagpur, India
Posts: 104
how to know which function belongs to which library?

as the title states..
what is the best way to know which function call belongs to which library?

I was coding in C and using GCC 4.x..
I know how to use System V IPC semaphores..
but I wanted to learn POSIX semaphores..
so i went through some internet tutorials and from manpages I could learn..
but I have no idea which library to link with my object file,
for my code to run.. I searched and searched.. after a long time I found it..
its like '-lrt'.. (no tute specified which lib to link )

so my question is in general how can one find the library to reference?
if I am stuck at such point.. man pages dont tell me which lib does this belong to..
they only tell me the header files..

I found some thread 2 years old on a forum asking to grep on /usr/lib/*
I did it and ended up with lot many results saying few matches found..
and one of them is libgc.. I didnt understand why I should be linking if its in libgc..
Also that grep didnt list 'librt'

can anyone help me?
__________________
C's Motto: who cares what it means? I just compile it!!
gibsosmat is offline   Reply With Quote
Old 11-17-2007, 08:49 PM   #2
Registered User
 
Join Date: Oct 2001
Posts: 2,110
it's in man pthreads. it's -lpthread.
robwhit is offline   Reply With Quote
Old 11-17-2007, 08:59 PM   #3
Devil™
 
Join Date: Oct 2007
Location: IIT-Kharagpur, India
Posts: 104
Quote:
Originally Posted by robwhit View Post
it's in man pthreads. it's -lpthread.
thanks..
I thought it was only a posix thread lib..
still which is the actual lib for posix IPC functions?

do you have any idea about my original prob?
__________________
C's Motto: who cares what it means? I just compile it!!
gibsosmat is offline   Reply With Quote
Old 11-17-2007, 10:01 PM   #4
Registered User
 
Join Date: Oct 2001
Posts: 2,110
yeah I was wrong. This page seems to agree with you:

http://linux.die.net/man/7/mq_overview
robwhit is offline   Reply With Quote
Old 11-17-2007, 10:56 PM   #5
Protocol Test Engineer
 
ssharish2005's Avatar
 
Join Date: Sep 2005
Location: fseek(UK)
Posts: 1,324
Quote:
what is the best way to know which function call belongs to which library?
I tend to get most of the linker flag names from their man page. Most of them tent to have it in their. But some dont.

ssharish
ssharish2005 is offline   Reply With Quote
Old 11-17-2007, 11:35 PM   #6
Devil™
 
Join Date: Oct 2007
Location: IIT-Kharagpur, India
Posts: 104
Quote:
Originally Posted by ssharish2005 View Post
I tend to get most of the linker flag names from their man page. Most of them tent to have it in their. But some dont.

ssharish
lol..
thats what I was doing
but I tried something like
-lpsem
-lposix
-lps
-lsem
-lsema
-lsemaphores
-lmut
-lmutex
etc

but the actual name was -lrt.. I have no clue why it is so..
may be it is meant for ppl who know which lib are you going to use and not which header followed by lib..
still there might be some elegant way to find it out..
else google is for free .. or Brows LSB..
__________________
C's Motto: who cares what it means? I just compile it!!
gibsosmat is offline   Reply With Quote
Old 11-17-2007, 11:38 PM   #7
Devil™
 
Join Date: Oct 2007
Location: IIT-Kharagpur, India
Posts: 104
Quote:
Originally Posted by robwhit View Post
yeah I was wrong. This page seems to agree with you:

http://linux.die.net/man/7/mq_overview
no prob.. may be that -lrt is not so famous..
I found on some mailing lists that -lrt got some problem with pthread..
(it was 3-4 years old message)
and was advised to used pthread for semaphores..

and after that found some proff's homepage yelling in red color to compile it with -lrt
__________________
C's Motto: who cares what it means? I just compile it!!
gibsosmat is offline   Reply With Quote
Old 11-18-2007, 01:24 AM   #8
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,680
If you just do a 'grep' on libraries, you find where the symbols are unresolved as well as defined.

If you want to find where a symbol is defined, then use this approach, then pipe through grep
Code:
$ nm --defined-only /usr/lib/lib*.a | more

/usr/lib/libautomode.a:

automode.o:
00000000 b .bss
00000000 d .data
00000000 r .rdata
00000000 t .text
00000000 T _cygwin_premain0
00000000 d pf.0

/usr/lib/libbfd.a:

archive.o:
00000000 b .bss
00000000 d .data
00000000 r .rdata
00000000 t .text
000000a8 r __PRETTY_FUNCTION__.0
000001e0 T __bfd_add_bfd_to_archive_cache
00000000 T __bfd_ar_spacepad
It lists the name of each library and each public symbol which can be found in that library.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 11-18-2007, 07:46 AM   #9
Devil™
 
Join Date: Oct 2007
Location: IIT-Kharagpur, India
Posts: 104
Quote:
Originally Posted by Salem View Post
If you just do a 'grep' on libraries, you find where the symbols are unresolved as well as defined.

If you want to find where a symbol is defined, then use this approach, then pipe through grep
Code:
$ nm --defined-only /usr/lib/lib*.a | more

/usr/lib/libautomode.a:

automode.o:
00000000 b .bss
00000000 d .data
00000000 r .rdata
00000000 t .text
00000000 T _cygwin_premain0
00000000 d pf.0

/usr/lib/libbfd.a:

archive.o:
00000000 b .bss
00000000 d .data
00000000 r .rdata
00000000 t .text
000000a8 r __PRETTY_FUNCTION__.0
000001e0 T __bfd_add_bfd_to_archive_cache
00000000 T __bfd_ar_spacepad
It lists the name of each library and each public symbol which can be found in that library.
wont this work for .so?
__________________
C's Motto: who cares what it means? I just compile it!!
gibsosmat is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined Reference Compiling Error AlakaAlaki C++ Programming 1 06-27-2008 11:45 AM
How to fix misaligned assignment statements in the source code? biggyK C++ Programming 28 07-16-2006 11:35 PM
c++ linking problem for x11 kron Linux Programming 1 11-19-2004 10:18 AM
I need help with passing pointers in function calls vien_mti C Programming 3 04-24-2002 10:00 AM
qt help Unregistered Linux Programming 1 04-20-2002 09:51 AM


All times are GMT -6. The time now is 11:55 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22