3

My program uses 'libone.so' object from certain vendor. It has custom location within a system. The program searches for this library location and then open it with dlopen. A problem appears when 'libone.so' do some stuff under the hood and starts to load 'libsecond.so'. I see with strace that dlopen tries to find 'libsecond.so' by standard paths defined for ldconfig, doesn't use the location of 'libone.so' as one of possible paths.

Is it possible to configure dlopen call within 'libone.so' so as it will load 'libsecond.so' from location of 'libone.so'? ('libsecond.so' located at the same path as 'libone.so')

ps. I can't affect on system configuration(ldconf paths) before program start. I need to resolve this problem within my program.

pss. If I add path to 'libone.so' to /etc/ld.so.conf.d/custom.conf then problem solved.

Zig Razor
  • 3,381
  • 2
  • 15
  • 35
dojo_user
  • 85
  • 10
  • 1
    Is `libsecond.so` loaded "automatically" or does `libeone.so` do some magic (like you)? – Max Langhof Jan 07 '20 at 10:50
  • Could you set / modify the execution environment? `LD_LIBRARY_PATH` environment variable could do the trick. – JL. Sanchez Jan 07 '20 at 10:50
  • @MaxLanghof libsecond.so is loaded automatically by libone.so. If both librires located by standard path(say /usr/lib) then no problem. My case is that location of this libraries is custom, I load first library and second library should be loaded by the first one. – dojo_user Jan 07 '20 at 10:54
  • @JL.Sanchez I tried to do it within my program using call of 'setenv' from stdlib.h for LD_LIBRARY_PATH right before "dlopen' for the first library but it didn't help. I can't set LD_LIBRARY_PATH in advance and can't start my program like: LD_LIBRARY_PATH=my_path ./my_program – dojo_user Jan 07 '20 at 10:57

1 Answers1

1

I think you have three options:

  1. Create a script file (e.g. bash, Python, etc) that sets LD_LIBRARY_PATH before executing your binary program and make it executable.

  2. Using -rpath linker option, add a fixed absolute path to the search paths which will be used by dynamic linker in addition to LD_LIBRARY_PATH.

  3. dlopen with absolute paths from bottom up. i.e. first dlopen dependencies then dlopen the main library.

I would prefer the first option.

frogatto
  • 28,539
  • 11
  • 83
  • 129