2

I have a .so in the path /home/test/lib/libTest.so and an executable called myexec that is built with RPATH pointing to /home/test/lib/. However, when I did ldd on myexec, it says libTest.so not found and I had to do export LD_LIBRARY_PATH in order for it to work.

I have confirmed:

  1. libTest.so does exist in /home/test/lib/
  2. objdump -x myexec | grep RUNPATH does indicate /home/test/lib/ is built into the executable.

Does anyone have idea why it couldn't find the library without setting LD_LIBRARY_PATH?

1
  • MVCE needed, Commented May 21, 2016 at 7:02

1 Answer 1

2

From here:

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

As a tip, you should be careful not to replace entirely your LD_LIBRARY_PATH. It could mess up the path for the system shared libraries. Always use export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/path.

EDIT 1:

As for the rpath, make sure that libTest.so doesn't depend on any other library. As an alternative you can use -rpath-link option in gcc instead of -rpath, as seen here:

-rpath-link DIR

When using ELF or SunOS, one shared library may require another. This happens when an ld -shared link includes a shared library as one of the input files. When the linker encounters such a dependency when doing a non-shared, non-relocateable link, it will automatically try to locate the required shared library and include it in the link, if it is not included explicitly. In such a case, the -rpath-link option specifies the first set of directories to search.

EDIT 2:

If you want more help, please provide:

  1. Exact parameter for rpath used during compile
  2. Output for ldd /path/to/binary command
  3. Output for readelf -d /path/to/binary
Sign up to request clarification or add additional context in comments.

2 Comments

Does this actually address the question? OP asked why an external environment variable (LD_LIBRARY_PATH) was necessary when the required path was already built into the executable.
I admit the answer was not satisfactory. I just edited it requesting more information. Sorry about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.