how to know which function belongs to which library?

This is a discussion on how to know which function belongs to which library? within the Linux Programming forums, part of the Platform Specific Boards category; as the title states.. what is the best way to know which function call belongs to which library? I was ...

  1. #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!!

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    it's in man pthreads. it's -lpthread.

  3. #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!!

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    yeah I was wrong. This page seems to agree with you:

    http://linux.die.net/man/7/mq_overview

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    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

  6. #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!!

  7. #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!!

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    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.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #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!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  4. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM

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