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.