Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find shared libraries even -rpath is set correctly

Tags:

ld

rpath

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.

like image 524
Peter VARGA Avatar asked Nov 16 '22 20:11

Peter VARGA


1 Answers

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

  1. Consider rpath vs runpath: you can change with

-Wl,--disable-new-dtags

  1. If your lib use other libs as dependency, must set it's rpath/runpath separately (in it's make process). It's is one of differences between LD_LIBRARY_PATH an rpath/runpath.
  2. You can use LD_DEBUG=libs ldd your_app/libyour_lib.so to check search paths of rpath/runpath.
like image 193
Mohammad Shokouhi Gol Avatar answered Nov 19 '22 09:11

Mohammad Shokouhi Gol