LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-03-2008, 10:03 PM   #1
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 49
Finding path of library


I have a library I've created. I also have my own application that uses this library.

Now, since in this day and age you can use a prefix and choose where to install applications, I would really much like to know, inside my library, where I am installed - since I know that I have some files scattered around in different places. I just don't know the prefix they used when they installed me.

So, to sum up: how can a class constructor inside a library (.so-file) find the path of the library.so-file?

Thanks!
 
Old 01-03-2008, 10:24 PM   #2
sundialsvcs
Senior Member
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 3,685

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
It's actually very difficult if not impossible to determine that... and, I would think, you really should not need to. You want the user to decide how-and-where he "found you." And you ought not need to know where that actually was.
 
Old 01-04-2008, 09:04 AM   #3
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 49
Quote:
Originally Posted by sundialsvcs View Post
It's actually very difficult if not impossible to determine that... and, I would think, you really should not need to. You want the user to decide how-and-where he "found you." And you ought not need to know where that actually was.
Ok, so maybe there is another solution to this problem:
My build/install system (which is cmake, btw) installs the library in $PREFIX/lib and also puts some files in $PREFIX/share/<myname>/

Now, I have a class constructor inside this library that needs to access those files inside the share-folder. But I don't know the prefix. :/
 
Old 01-05-2008, 07:23 PM   #4
theNbomr
Senior Member
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 4,506

Rep: Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602
Where the library is stored and found by the linker/loader should be completely independent of any filesystem references embedded within its object code. The behavior of the runtime code should be identical no matter where the loader finds the library.
What is more germane to the question would be the 'present working directory', which always has some value that refers to a place in the filesystem. Paths expressed at runtime can be either absolute (relative to '/' ) or relative to the current working directory. The concept of current working directory holds on a per-process basis, so the same runtime binary may execute from almost any current working directory, and may also change directories at runtime. Nothing you build into a library (except code that explicitly changes directories) can change this, nor can you change this by storing your libraries differently.

--- rod.
 
Old 01-05-2008, 08:22 PM   #5
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 49
Quote:
Originally Posted by theNbomr View Post
Where the library is stored and found by the linker/loader should be completely independent of any filesystem references embedded within its object code. The behavior of the runtime code should be identical no matter where the loader finds the library.
What is more germane to the question would be the 'present working directory', which always has some value that refers to a place in the filesystem. Paths expressed at runtime can be either absolute (relative to '/' ) or relative to the current working directory. The concept of current working directory holds on a per-process basis, so the same runtime binary may execute from almost any current working directory, and may also change directories at runtime. Nothing you build into a library (except code that explicitly changes directories) can change this, nor can you change this by storing your libraries differently.

--- rod.
Yeah, so you told me what not to do.. And I understand your point. But you haven't given me any ideas to a solution to my problem.

Maybe you missed it:

CASE 1
The user installs my library with prefix: /usr/local

The library gets installed by the build system to:
/usr/local/lib/libdynapt.so
The build system also installs some important files:
/usr/local/share/dynapt/chii.rpe, among others...

CASE 2
The next user uses another prefix: /usr
Library: /usr/lib/libdynapt.so
Files: /usr/share/dynapt/chii.rpe



Now, my application (called Tricera) is linked (-ldynapt) and creates an instance of a class which is defined inside the library, let's call it ClassHideki();

Problem is, there's a lot of stuff going on inside this ClassHideki and eventually we get down to a class that needs to access those extra files (for example chii.rpe). Now, I am trying to remove the hardcoded path /usr/share/dynapt/chii.rpe from my source, making it work with other prefixes.

Have in mind that I, thorugh ClassHideki(), may need to let Tricera get the path to chii.rpe for some reason.

So, what you are saying is that I should not "calculate" the path to chii.rpe depending on where libdynapt.so is. I got that.

So any other ideas how to find this file?

EDIT: It doesn't have to be runtime, I know that. But still, I need help here.. I am no good at either cmake or the #<stuff>.. :P

Last edited by Ephracis; 01-05-2008 at 08:27 PM.
 
Old 01-08-2008, 08:56 AM   #6
theNbomr
Senior Member
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 4,506

Rep: Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602
You are trying to do work that the loader does. When you create a runtime binary that uses shared object libraries, the linking loader resolves all of these issues for you. It uses the information in $LD_LIBRARY_PATH and/or /etc/ld.so.conf to find the necessary libraries. Your runtime code doesn't need to do anything to go out and locate its own object code.
--- rod.
 
Old 01-08-2008, 09:20 AM   #7
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 49
Quote:
Originally Posted by theNbomr View Post
You are trying to do work that the loader does. When you create a runtime binary that uses shared object libraries, the linking loader resolves all of these issues for you. It uses the information in $LD_LIBRARY_PATH and/or /etc/ld.so.conf to find the necessary libraries. Your runtime code doesn't need to do anything to go out and locate its own object code.
--- rod.
No, my goal is not to locate the .so-file. I want to locate the files inside $PREFIX/share/dynapt/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
finding openssl library? vbsaltydog Fedora 2 07-13-2007 09:47 AM
ImageMagick configure not finding libjpeg library thetawaverider Linux - Software 2 11-06-2006 08:25 AM
library path Scott7 Debian 1 10-19-2005 07:25 AM
finding the PATH tahiche Linux - Software 7 10-12-2005 12:47 PM
GD Library path? kinkybullet Linux - Newbie 1 02-11-2004 09:15 PM


All times are GMT -5. The time now is 04:31 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration