Peter VARGA
Peter VARGA

Reputation: 5196

Cannot find shared libraries even -rpath is set correctly

I am building a third party program which is using libraries from a directory which is not set in /etc/ld.so.conf - therefore I link the program with the -rpath option.

Running objdump -x bin/GetHistPrices | grep -i path to check if -rpath is set correctly I get the confirmation it is OK:

RUNPATH 
   /application/FXCM-API/GetHistPrices/bin:
   /application/FXCM-API/lib:
   /application/FXCM-API/sample_tools/lib

cmake copies all libraries into the same directory where the executable is generated [e.q. ../GetHistPrices/bin]; therefore the 1st path is OK.

Even more, the last 2 paths point also to directories where the shared libraries are located - these -rpath options are added automatically by the cmake script.

When I try to run the program NOT inside the ../GetHistPrices/bin/ directory [where it is located] - e.q. I don't execute it with ./GetHistPrices - so I get this error message:

bin/GetHistPrices: error while loading shared libraries:

  libgsexpat.so: cannot open shared object file: No such file or directory

The program only gets started when I either run it from the bin/ or /application/FXCM-API/lib directory because the needed library is located there.

1)
When I run the program with
LD_LIBRARY_PATH="/application/FXCM-API/GetHistPrices/bin" bin/GetHistPrices
then it starts. But this is what I see as well in the executable. Strange!

2)
Adding /application/FXCM-API/GetHistPrices/bin to /etc/ld.so.conf let start the program as well successfully.

OS is SLES 12.3 - honestly, somehow it looks to me like a bug in the system.

My question:

What am I doing wrong that it doesn't work even RUNPATH is correctly set in the executable.

Upvotes: 6

Views: 4027

Answers (1)

Mohammad Shokouhi Gol
Mohammad Shokouhi Gol

Reputation: 409

It may be late to answer but it may be useful for others. Some notes:

  1. Consider rpath vs runpath: you can change with

-Wl,--disable-new-dtags

  1. If your lib uses other libs as dependencies, you must set its rpath/runpath separately (in its make process). It is one of the differences between LD_LIBRARY_PATH and rpath/runpath.
  2. You can use LD_DEBUG=libs ldd your_app/libyour_lib.so to check search paths of rpath/runpath.

Upvotes: 9

Related Questions