0

I'm trying to build a shared object library but when I produce the shared object library it says the object file is not found.

OSError: lib1.o: cannot open shared object file: No such file or directory

I then ran ldd command to check what the dependencies are

linux-vdso.so.1 =>  (0x00007fff47dff000)
lib1.o => not found
lib2.o => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f61023db000)
/lib64/ld-linux-x86-64.so.2 (0x00007f610297c000)

I'm compiling gcc with the following command.

gcc -I ../../path1/include -I ../../path2/include --shared -fPIC file1.c -o lib1.o gcc -I ../../path1/include -I ../../path3/include --shared -fPIC file2.c -o lib2.o gcc lib1.o lib2.o -shared -o lib2.so

I found a quick solution which is to set the environment variable LD_LIBRARY_PATH to the path that lib1.o and lib2.o are located but this needs to be run upon every login. I want a solution where it just works. Why can't it find the object files? Is there a way for the shared object files to contain the object files so no path specification is required?

tyleax
  • 101
  • 3
  • 2
    Possible duplicate of [Linux : Alternative of install\_name\_tool of MAC in CentOS](https://unix.stackexchange.com/questions/25653/linux-alternative-of-install-name-tool-of-mac-in-centos) – thrig Jan 18 '18 at 21:11
  • 2
    See the `--rpath` and `--rpath-link` options of the `ld` command. You can also edit `/etc/ld.so.conf` or add/change files in the `/etc/ld.so.conf.d` directory. I would be weary of executables looking for shared libraries in relative directories. – Deathgrip Jan 18 '18 at 22:23

0 Answers0