Hailiang Zhang
Hailiang Zhang

Reputation: 18950

LD_LIBRARY_PATH changed between linking and running

Say we have 2 libraries (A and B) with the same SONAME and interfaces. The developers linked against A when compiling, but the users set $LD_LIBRARY_PATH before running. Everything is quite normal, but the users don't know they have used a different library from what the developer wanted.

I am a learner of compilation, and not sure this is just a hack and should be avoided or not. I know providing "-Wl,--rpath" to the compiler will prioritize the runtime linking path, but not sure what is the most "standard" strategy in software development.

Upvotes: 0

Views: 77

Answers (1)

Nikos C.
Nikos C.

Reputation: 51910

If users set LD_LIBRARY_PATH, it means they do know that they get a different library. It's why they set LD_LIBRARY_PATH in the first place. If they wanted the default library, they wouldn't have set that env var. It's a very explicit setting to make and means "I know what I'm doing and I have my reasons."

As for answering the actual question, rpath is a standard method and many libraries use it or offer it as a build-time configuration option. Are you sure it overrides LD_LIBRARY_PATH though? AFAIK, it does not. And it's not supposed to, as that would leave users no way of altering the default library search path.

Upvotes: 1

Related Questions