0

I have the following sources (simplified as possible):

foo.c --> the main executable ${MAIN_FOLDER}/foo, dlopens bar.so from runtime provided path.

bar.c --> shared library /bar.so, dlopends baz.so from the path relative to foo

baz.c --> ${MAIN_FOLDER}/lib/baz.so, some implementation.

What I need to achieve is make bar.so see baz.so when loaded from foo. I am looking for either some C code I can issue in foo before it calls dlopen or linker flags to provide to bar.so linking step.

I tried setting rpath for bar.so, but it didn't work as $ORIGIN is the location of bar.so, not foo. Setting RPATH in foo (which works, RPATH with proper ORIGIN is passed to loading process of bar.so) is unfortunately not an option (cannot do that due to formal restrictions I won't be able to change), I can change the code of foo.c though. Also, using path relative to $CWD does not solve the problem (no idea what location the program is going to be called from).

The attempt to setenv LD_LIBRARY_PATH in foo before loading bar.so failed as well.

This time I am not interested in portability, I only need solution for Linux for now.

ciesizdz
  • 61
  • 1
  • 5
  • "The attempt to setenv LD_LIBRARY_PATH in foo before loading bar.so failed as well" - interesting, that's probably because dynamic linker only parses it once during startup and ignores subsequent modifications. – yugr Jan 30 '17 at 17:31
  • That's right, I didn't expect it to work but tried anyway. – ciesizdz Jan 31 '17 at 09:58
  • Sadly the trick with `dlopen`ing baz.so prior to bar.so does not help. – yugr Jan 31 '17 at 10:50

0 Answers0