Runtime linker, adding path to parent executable to the resolution path
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.
链接地址: http://www.djcxy.com/p/46450.html上一篇: 简单的nodejs http代理失败,“打开的文件太多”
下一篇: 运行时链接程序,将父路径添加到解析路径