How to get the absolute path of the library currently loaded?

B

bruno.fischel

Hi,

I was wondering if there was a way to know the absolute path of the
library "currently running".
For example, in my function foo, how can I get the path of the library
containing the definition of foo?

The library path will be different from the "current directory" (.)
since the current directory will be the directpry of the prgram that
loaded the lib; not the path to the library itself.

Otherwise, do you know fi the STL library provide a "registry service"
(like the java Preferences API)?

Thanks a lot for your help
 
I

Ian Collins

Hi,

I was wondering if there was a way to know the absolute path of the
library "currently running".
For example, in my function foo, how can I get the path of the library
containing the definition of foo?

The library path will be different from the "current directory" (.)
since the current directory will be the directpry of the prgram that
loaded the lib; not the path to the library itself.
That's very platform specific, some platforms might not even have
libraries or directories.

Better ask on a group specific to your platform.
Otherwise, do you know fi the STL library provide a "registry service"
(like the java Preferences API)?
No.
 
V

Victor Bazarov

I was wondering if there was a way to know the absolute path of the
library "currently running".

There can be. However, it would be a feature of the OS, not of the
language.
In C++ what's "running" is the program, not "the library". The host system
_may_ provide the command with which it was started, in the 'argv[0]' (see
the 'main' function), or it may not, it's up to the system. Many systems
do,
yet some don't.
For example, in my function foo, how can I get the path of the library
containing the definition of foo?

C++ defines the _language_. In C++ you can find the _translation unit_ in
which the *code* is contained (see __FILE__ macro). The rest is platform-
and implementation-specific (and off-topic here).
The library path will be different from the "current directory" (.)
since the current directory will be the directpry of the prgram that
loaded the lib; not the path to the library itself.

All those things are unknown to C++.
Otherwise, do you know fi the STL library provide a "registry service"
(like the java Preferences API)?

Nothing like that in the Standard.

V
 
A

Aman Angrish

I was wondering if there was a way to know the absolute path of the
library "currently running".
For example, in my function foo, how can I get the path of the library
containing the definition of foo?

on unix : ldd ./a.out (./a.out is the executable )
macosX : oTool ./a.out

regards,
Aman Angrish.
 
T

Thobias Vakayil

Hi,

I was wondering if there was a way to know the absolute path of the
library "currently running".
For example, in my function foo, how can I get the path of the library
containing the definition of foo?

The library path will be different from the "current directory" (.)
since the current directory will be the directpry of the prgram that
loaded the lib; not the path to the library itself.

Otherwise, do you know fi the STL library provide a "registry service"
(like the java Preferences API)?

Thanks a lot for your help
In unix type the following command :
$ ldd <executable name>

If you want to attach the libraries at the time of running, you have
update the LD_LIBRARY_PATH
Regards,

Thobias Vakayil
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top