Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link to shared lib from shared lib with relative path?

Tags:

I'm working on a Firefox plugin that uses external libraries to render 3D graphics on the browser.

The problem is that I want the plugin to use external libraries packed with it without changing the LD_LIBRARY_PATH variable.
The libraries are installed in a position relative to the plugin (a shared library too), while the actual executable (i.e. the browser) can be located somewhere entirely else.

I'm testing it on Ubuntu (no problem at Windows version of the plugin) My dependencies are OpenSceneGraph libraries and static compilation will make the plugin really big (not an option if there is another one).

like image 688
leosamu Avatar asked Oct 18 '10 15:10

leosamu


People also ask

How shared library are linked?

Shared libraries (also called dynamic libraries) are linked into the program in two stages. First, during compile time, the linker verifies that all the symbols (again, functions, variables and the like) required by the program, are either linked into the program, or in one of its shared libraries.

How do you reference a relative path?

Relative path Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy. A single dot represents the current directory itself.

Can RPATH be relative?

The RPATH entries for directories contained within the build tree can be made relative to enable relocatable builds and to help achieve reproducible builds by omitting the build directory from the build environment.

Does chdir work with relative path?

Description: The chdir() function changes the current working directory to path, which can be relative to the current working directory or an absolute path name.


1 Answers

Use the rpath option when linking and specify the 'special' path $ORIGIN.

Example:

-Wl,-R,'$ORIGIN/../lib' 

Here's a site that elaborates on using $ORIGIN: http://www.itee.uq.edu.au/~daniel/using_origin/

like image 169
lothar Avatar answered Oct 09 '22 09:10

lothar