Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have an executable linked like this:

  $ ldd a.out => /usr/lib64/ (0x00007f4881f56000) => /usr/lib64/ (0x00007f4881cfb000) => /usr/lib64/ (0x00007f4881965000) => /lib64/ (0x00007f488175d000) => /lib64/ (0x00007f4881540000) => /usr/lib64/ (0x00007f4881239000)

Where the libcrypto and libssl libraries are openssl 1.0.0-fips libs. I want to experiment with the 1.0.1 libraries instead, and so I've built them in my home directory. Is there a way to get a.out to relink against my new openssl libraries without a lot of pain? I would like to avoid

  • Having to relink a.out (because the build tools are massively complicated)
  • Altering any global settings (because other devs work on this machine)

Is it possible to do what I'm hoping here?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

You can temporarily substitute a different library for this particular execution. In Linux, the environment variable LD_LIBRARY_PATH is a colon-separated set of directories where libraries should be searched for first, before the standard set of directories; this is useful when debugging a new library or using a nonstandard library for special purposes. The environment variable LD_PRELOAD lists shared libraries with functions that override the standard set, just as /etc/ does. - Shared Libraries

You can also invoke the loader directly:

/lib/ --library-path path executable

share|improve this answer

Write a wrapper script that sets the LD_LIBRARY_PATH environment variable. This is the pendant of PATH for shared libraries. The system search path is always searched after the directories listed in $LD_LIBRARY_PATH. See the dynamic linker manual for reference.

export LD_LIBRARY_PATH=~/opt/openssl-1.0.1/lib
exec /path/to/a.out "$@"

Or, for a one-off, directly on the command line:

LD_LIBRARY_PATH=~/opt/openssl-1.0.1/lib ./a.out

Alternatively, if you want to modify the binary, try chrpath, which lets you edit the library search path baked in the executable.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.