Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Getting path of a shared object from inside it

Reply
Thread Tools

Getting path of a shared object from inside it

 
 
sug
Guest
Posts: n/a
 
      06-21-2005
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

 
Reply With Quote
 
 
 
 
Jean-Claude Arbaut
Guest
Posts: n/a
 
      06-21-2005



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
>


 
Reply With Quote
 
 
 
 
Jean-Claude Arbaut
Guest
Posts: n/a
 
      06-21-2005



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" ?

 
Reply With Quote
 
sug
Guest
Posts: n/a
 
      06-21-2005
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

 
Reply With Quote
 
Jean-Claude Arbaut
Guest
Posts: n/a
 
      06-21-2005



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.

 
Reply With Quote
 
Jean-Claude Arbaut
Guest
Posts: n/a
 
      06-21-2005



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.

 
Reply With Quote
 
Paul Pluzhnikov
Guest
Posts: n/a
 
      06-21-2005
"sug" <(E-Mail Removed)> 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/pser.../loadquery.htm

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

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      06-21-2005
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
set path to a shared object knguyen C++ 1 02-20-2008 08:00 PM
Getting a Log Folder Reference Path inside a helper project -- Please read Rahul ASP .Net Web Services 1 12-07-2006 05:09 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
how to get application path? Is that my method in getting path wrong? James Java 2 12-07-2004 11:59 AM
built with --enable-shared but get error: libpython2.3.so.1.0: can't open shared object file Douglass Turner Python 2 09-04-2003 01:56 PM



Advertisments