13

I am trying to make the postgis extension work on my system and it always spits out "$libdir/postgis2.2" no such file or directory error. For my curiosity I executed "ldd postgis-2.2.so" and it spits out the following result :

    linux-vdso.so.1 =>  (0x00007ffff3bc8000)
    /usr/lib64/libjemalloc.so.1 (0x00002b3fe5ff4000)
    libgeos_c.so.1 => not found
    libproj.so.9 => not found
    libjson-c.so.2 => not found
    libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x00002b3fe6237000)
    libm.so.6 => /lib64/libm.so.6 (0x00002b3fe659e000)
    libc.so.6 => /lib64/libc.so.6 (0x00002b3fe689c000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b3fe6c41000)
    /lib64/ld-linux-x86-64.so.2 (0x00002b3fe5b2e000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00002b3fe6e5d000)
    libz.so.1 => /lib64/libz.so.1 (0x00002b3fe7061000)
    liblzma.so.5 => /usr/lib64/liblzma.so.5 (0x00002b3fe7277000)

And for a bunch of dependencies I see the path to their so is not present. This I guess is happening because I am not building postgis but just copying the required so's and libs to make it work manually. But I do know the path to those so files that are required by postgis. What should I do such that I can change the "not found" in dependencies to the required path by postgis?

AnkitSablok
  • 303
  • 1
  • 2
  • 7

2 Answers2

10

ld.so, the dynamic linker, will use the PATH-like environment variable LD_LIBRARY_PATH when it looks for shared libraries to link at execution time.

You may set LD_LIBRARY_PATH to a :-delimited list of directories where the linker should look for libraries, for example:

$ env LD_LIBRARY_PATH="$HOME/local/lib:/opt/other/lib" ./myprog

See the ld.so manual on your system for more information.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
7

This has been covered in part in many tutorials, but I feel many of the solutions are missing a basic example.

Assuming you're using for Linux:

Note: patchelf is not installed by default on many systems. You can install it using apt install patchelf, dnf install patchelf, pacman install patchelf or whatever your package manager provides.

patchelf --print-needed mysharedobject.so

# outputs:
../libsomething1.so
libsomething2.so.1

Replace the path to a required library:

patchelf --replace-needed ../libsomething1.so /foo/bar/libsomething1.so mysharedobject.so

Test the new path:

patchelf --print-needed mysharedobject.so

# outputs:
/foo/bar/libsomething1.so 
libsomething2.so.1

Note: Many tutorials recommend another tool called chrpath which can help .so files that have a rpath attribute set but it does not appear to work with libraries missing rpath nor have the ability to change the absolute link location.

tresf
  • 273
  • 2
  • 8
  • `patchelf --replace-needed` does the job , however the `rpath` printed by `ldd` remains same as original dependency path – Mohammad Kanan Aug 23 '22 at 19:12
  • 1
    I believe you will want to use [`chrpath`](https://unix.stackexchange.com/questions/272279/how-to-change-the-paths-to-shared-libraries-so-files-for-a-single-terminal-in) for that. – tresf Aug 25 '22 at 00:51