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?