0

I built a project to a python lib and after that I want to migrate and run the lib to server or any other machine. but I meet a dependency problem: enter image description here

The .so file cysteps_dist.so in the lib step folder has some dependend .so libraries located in the temporary build folder. If I just copy the lib step folder to other machine, it won't work.

So, I want to copy these dependend libraries (example libomega_h.so and libsundials_cvode.so.3 and any potentially missing library file) to the same step folder.

enter image description here

I want to change the env variable LD_LIBRARY_PATH when I use import steps so that the copied libraries can be found.

But I don't want to use command export LD_LIBRARY_PATH=/usr/lib/python3/dist-packages/steps every time before command import steps. So I am looking for a way to change the __init__.py file or any other source file in the step folder to achieve this "specify env variable" effect.

I tried some code like followed but failed:

import os
if not 'LD_LIBRARY_PATH' in os.environ:
    os.environ["LD_LIBRARY_PATH"] = os.path.dirname(__file__)
else:
    os.environ["LD_LIBRARY_PATH"] = os.path.dirname(__file__) + ":" + os.environ["LD_LIBRARY_PATH"]

os.execve(os.path.realpath(__file__), (' ',), os.environ)

so, how to make the .so file find its dependencies in its file location?

Z.Lun
  • 247
  • 1
  • 2
  • 20
  • Why don't you just place those files in `/usr/local/lib` so they are universally available? – Tim Roberts Jun 26 '23 at 00:31
  • @TimRoberts That's a good idea. I just want to know how to achive this effert and it's more like easy to deploy. and there is a another way which use some option when compiling them, but I don't want to go deep in details of these opensource libs. – Z.Lun Jun 26 '23 at 01:51

1 Answers1

0

for my question, if I don't want to go deep in details of compling. I need to modify the rpath of the shared library.

from:q1 and q2 I just need to install chrpath via apt install chrpath then run commands as follows:

patchelf --set-rpath '$ORIGIN/:'`patchelf --print-rpath cysteps_dist.so` cysteps_dist.so
patchelf --print-rpath cysteps_dist.so

in this case I get:

# patchelf --print-rpath cysteps_dist.so
/root/STEPS/build/_bundle/SUNDIALS-install/lib:/usr/lib/petscdir/petsc3.12/x86_64-linux-gnu-real/lib:/root/STEPS/build/_bundle/omega_h-install/lib:/usr/lib/x86_64-linux-gnu/openmpi/lib:
# patchelf --set-rpath '$ORIGIN/:'`patchelf --print-rpath cysteps_dist.so` cysteps_dist.so 
# patchelf --print-rpath cysteps_dist.so 
$ORIGIN/:/root/STEPS/build/_bundle/SUNDIALS-install/lib:/usr/lib/petscdir/petsc3.12/x86_64-linux-gnu-real/lib:/root/STEPS/build/_bundle/omega_h-install/lib:/usr/lib/x86_64-linux-gnu/openmpi/lib:

then I can migrate this lib to everywhere with shared libraries together.

Z.Lun
  • 247
  • 1
  • 2
  • 20