Thijs Koerselman
Thijs Koerselman

Reputation: 23310

How to link shared libraries in local directory, OSX vs Linux

I have some shared/dynamic libraries installed in a sandbox directory. I'm building some applications which link agains the libraries. I'm running into what appears to be a difference between OSX and Linux in this regard and I'm not sure what the (best) solution is.

On OSX the location of library itself is recorded into the library, so that if your applications links against it, the executable knows where to look for the library at runtime. This works like expected with my sandbox, because the executable looks there instead of system wide install paths.

On Linux I can't get this to work. Apparently the library location is not present in the library itself. As I understand it you have to add the folders which contain libraries to /etc/ld.so.conf and regenerate the ld cache by running ldconfig.

This doesn't seem to do the trick for me because my libraries are located inside a users home directory. It looks like ldconfig doesn't like that, which makes sense actually.

How can I solve this? I don't want to move the libraries out of my sandbox.

Upvotes: 2

Views: 3229

Answers (2)

James Morris
James Morris

Reputation: 4955

On Linux you should set LD_RUN_PATH to your sandbox dir. This is better than setting LD_LIBRARY_PATH because you're telling the linker where the library is at link time, rather than telling the shared library loader at run time.

See: Link

Upvotes: 1

Fred Foo
Fred Foo

Reputation: 363817

On Linux, run your program with the environment variable LD_LIBRARY_PATH set to your sandbox dir.

(I remember having used a flag -R to include library paths in the binary, but either it has been removed from gcc or it was only available on BSD systems.)

Upvotes: 2

Related Questions