tags:

views:

440

answers:

4

Hi.

I read some articles about problems in using the LD_LIBRARY_PATH, even as a part of a wrapper script:

http://linuxmafia.com/faq/Admin/ld-lib-path.html

http://blogs.sun.com/ali/entry/avoiding_ld_library_path_the

In this case - what are the recommended alternatives?

Thanks.

+2  A: 

Hmmm... I've always set LD_LIBRARY_PATH, and I've never has a problem.

To quote you first link:

When should I set LD_LIBRARY_PATH? The short answer is never. Why? Some users seem to set this environment variable because of bad advice from other users or badly linked code that they do not know how to fix.

That is NOT what I call a definative problem statement. In fact it brings to mind I don't like it. [YouTube, but SFW].


That second blog entry (http://blogs.sun.com/ali/entry/avoiding_ld_library_path_the) is much more forthcoming on the nature of the problem... which appears to be, in a nutshell, library version clashes ThisProgram requires Foo1.2, but ThatProgram requires Foo1.3, hence you can't run both programs (easily). Noite that most of these problems are negated by a simple wrapper script which sets the LD_LIBRARY_PATH for just the executing shell, which is (almost allways) a seperate child process of interactive shell.

Note also that the alternatives are pretty well explained in post.

I'm just confused as to why you would post a question containing links to articles which apparently answer your question... Do you have a specific question which wasn't covered (clearly enough) in either of those articles?

Cheers. Keith.

corlettk
+4  A: 

the answer is in the first article you quoted.

In UNIX the location of a library can be specified with the -L dir option to the compiler. .... As an alternative to using the -L and -R options, you can set the environment variable LD_RUN_PATH before compiling the code.

SpliFF
@Scoob: LD_RUN_PATH presumes forknowledge of the runtime environment... which is fine if you're building and running on the same machine, but should be avoided for distributable (or even migratable) ELF's... I can't see how specifying LD_RUN_PATH can hurt, but it might not help ;-0
corlettk
+2  A: 

You can try adding:

-Wl,-rpath,path/to/lib

to the linker options. This will save you the need to worry about the LD_LIBRARY_PATH environment variable, and you can decide at compile time to point to a specific library.

Gilad Naor
A: 

Why LD_LIBRARY_PATH is bad and what to do instead.

sigjuice
Fixed broken link. SO doesn't handle archive.org URL with http:// in it.
sigjuice