2

I know I can modify library search path by setting LD_LIBRARY_PATH etc., but this approach is sometimes lame. I really want to have /usr/local/lib in the default path, but unfortunately, this seems non-default in GNU/Linux. (I've had quite a few problems with /usr/local/lib before, and installing the same libraries in /usr/lib instead solved those problems. But I really don't want to mess with /usr/lib.)

So, is it possible to modify the default library path once and for all? Thanks.

2 Answers 2

5

In Linux, you can edit the entries in /etc/ld.so.conf

You can also alter the default search path directly in the compiled executable by passing

-R /usr/local/lib

to the C compiler.

You can inspect the compiled-in search path of an executable with:
readelf -d <file> | grep RPATH

There's a fuller description here.

Sign up to request clarification or add additional context in comments.

2 Comments

If you edit /etc/ld.so.conf don't forget to run ldconfig as root afterwards.
Ah. Good point. I got caught out by that myself, the first time.
1

It is better to change library path to a certain binary:

patchelf --set-rpath=/usr/local/lib:/usr/lib my_binary 

1 Comment

I don't know if patchelf is better, but it should be combined with the above answer. It provides a build option to set a RUNPATH.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.