Getting path of a shared object from inside it

Discussion in 'C Programming' started by sug, Jun 21, 2005.

  1. sug

    sug Guest

    Hi,

    I am running a C program on Unix which loads a shared object of mine.

    I need to get the path of my .so from inside it. I want to do this
    because from my .so I want to open a text file which is in same
    directory as my .so.

    getcwd() obviously doesn't serve my purpose because my .so is not in
    "cwd" but I am pointing my executable to it using the
    LIBPATH/LD_LIBRARY_PATH.

    Can somebody provide any pointers? Thanks in advance


    Sug
     
    sug, Jun 21, 2005
    #1
    1. Advertising

  2. Re : Getting path of a shared object from inside it

    On 21/06/2005 14:40, sug wrote:

    > Hi,
    >
    > I am running a C program on Unix which loads a shared object of mine.
    >
    > I need to get the path of my .so from inside it. I want to do this
    > because from my .so I want to open a text file which is in same
    > directory as my .so.
    >
    > getcwd() obviously doesn't serve my purpose because my .so is not in
    > "cwd" but I am pointing my executable to it using the
    > LIBPATH/LD_LIBRARY_PATH.
    >
    > Can somebody provide any pointers? Thanks in advance
    >
    >
    > Sug
    >
     
    Jean-Claude Arbaut, Jun 21, 2005
    #2
    1. Advertising

  3. On 21/06/2005 14:40, sug wrote:

    > Hi,
    >
    > I am running a C program on Unix which loads a shared object of mine.
    >
    > I need to get the path of my .so from inside it. I want to do this
    > because from my .so I want to open a text file which is in same
    > directory as my .so.
    >
    > getcwd() obviously doesn't serve my purpose because my .so is not in
    > "cwd" but I am pointing my executable to it using the
    > LIBPATH/LD_LIBRARY_PATH.
    >
    > Can somebody provide any pointers? Thanks in advance


    I think it's implementation dependent. You should have a look at your
    dynamic linker documentation. Maybe "man dyld" ?
     
    Jean-Claude Arbaut, Jun 21, 2005
    #3
  4. sug

    sug Guest

    Re: Re : Getting path of a shared object from inside it

    Hi Jean,

    Thanks. I am not sure but I guess "dyld" is a utility right?
    I need to do it from my code, I probably need a function that I can
    call from C. Or you were poining at doing system("dyld")?

    Thanks, Sug
     
    sug, Jun 21, 2005
    #4
  5. On 21/06/2005 15:01, sug wrote:

    > Hi Jean,
    >
    > Thanks. I am not sure but I guess "dyld" is a utility right?
    > I need to do it from my code, I probably need a function that I can
    > call from C. Or you were poining at doing system("dyld")?
    >
    > Thanks, Sug
    >


    No, actually, dyld is the dynamic linker on my platform, I don't know its
    name on yours. Basically, it's the program that loads executables and ".so"
    files, and it provides functions to access the object "headers", which
    provide many important informations. On your platform I suppose there is
    something similar.
     
    Jean-Claude Arbaut, Jun 21, 2005
    #5
  6. On 21/06/2005 15:09, Jean-Claude Arbaut wrote:

    >
    >
    >
    > On 21/06/2005 15:01, sug wrote:
    >
    >> Hi Jean,
    >>
    >> Thanks. I am not sure but I guess "dyld" is a utility right?
    >> I need to do it from my code, I probably need a function that I can
    >> call from C. Or you were poining at doing system("dyld")?
    >>
    >> Thanks, Sug
    >>

    >
    > No, actually, dyld is the dynamic linker on my platform, I don't know its
    > name on yours. Basically, it's the program that loads executables and ".so"
    > files, and it provides functions to access the object "headers", which
    > provide many important informations. On your platform I suppose there is
    > something similar.
    >


    To be more explicit: these functions are available in C programs.
     
    Jean-Claude Arbaut, Jun 21, 2005
    #6
  7. "sug" <> writes:

    > I need to get the path of my .so from inside it.


    [Followup-To: comp.unix.aix set since this is OS specific and has
    nothing to do with solaris or c.l.c]

    Call loadquery(L_GETINFO, ...)
    http://publib16.boulder.ibm.com/pseries/en_US/libs/basetrf1/loadquery.htm

    Interpreting the result from loadquery() is a bit tricky. You'll
    find sample code here:
    http://groups-beta.google.com/group/comp.unix.aix/msg/77cb479c1e8440c4

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.
     
    Paul Pluzhnikov, Jun 21, 2005
    #7
  8. sug

    CBFalconer Guest

    Jean-Claude Arbaut wrote:
    > On 21/06/2005 15:09, Jean-Claude Arbaut wrote:
    >> On 21/06/2005 15:01, sug wrote:
    >>
    >>> Thanks. I am not sure but I guess "dyld" is a utility right?
    >>> I need to do it from my code, I probably need a function that I
    >>> can call from C. Or you were poining at doing system("dyld")?

    >>
    >> No, actually, dyld is the dynamic linker on my platform, I don't
    >> know its name on yours. Basically, it's the program that loads
    >> executables and ".so" files, and it provides functions to access
    >> the object "headers", which provide many important informations.
    >> On your platform I suppose there is something similar.

    >
    > To be more explicit: these functions are available in C programs.


    And, instead of cluttering up c.l.c with 4 or more off-topic
    replies, you could have limited yourself to one setting followups
    to a more appropriate newsgroup. The fact that the OP failed to do
    so is no excuse.

    --
    Some informative links:
    news:news.announce.newusers
    http://www.geocities.com/nnqweb/
    http://www.catb.org/~esr/faqs/smart-questions.html
    http://www.caliburn.nl/topposting.html
    http://www.netmeister.org/news/learn2quote.html
     
    CBFalconer, Jun 21, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DJ Dev
    Replies:
    3
    Views:
    16,242
    Gandalf
    Feb 8, 2004
  2. James
    Replies:
    2
    Views:
    13,957
    Andrew Thompson
    Dec 7, 2004
  3. Douglass Turner
    Replies:
    2
    Views:
    2,102
    Manfred Bartz
    Sep 4, 2003
  4. knguyen

    set path to a shared object

    knguyen, Feb 20, 2008, in forum: C++
    Replies:
    1
    Views:
    368
    Victor Bazarov
    Feb 20, 2008
  5. Rahul
    Replies:
    1
    Views:
    191
    Catalin T
    Dec 7, 2006
Loading...

Share This Page