My shared library libnew.so uses some symbols form an already built third-party shared library libold.so. I would like to build an executable binary file that should be only linked against libnew.so. But it still needs to be linked against libold.so too. Otherwise, the linker complains about undefined reference to symbol... .I used these commands to build libnew.so and the executable file. For some reason, it is only allowed to use the current directory and I cannot put my files somewhere else.Btw, nm libnew.so shows symbols from libold.so as undefined. ldd libnew.so also does not report any libold.so. If I do not use libold.so for building libnew.so, the size of libnew.so will not be changed!For libnew.so :gcc -Wall -fPIC -c libnew.cgcc -shared -Wl,-soname,libnew.so.1 -o libnew.so.1.0 *.o -L. -loldln -sf libnew.so.1.0 libnew.so.1ln -sf libnew.so.1.0 libnew.soFor the executable :#this does not work and needs -lold as well.gcc -Wall main.c -L. -lnew -o progIs there anything missing? Thanks!
how to link against only the last shared library
gcc;c;ld
What is missing is that your linker commandgcc -shared -Wl,-soname,libnew.so.1 -o libnew.so.1.0 *.o -L. -lolddoes not copy objects from libold.so, but refers to symbols in that file to tell the dynamic loader where it can obtain those symbols.Normally when someone is trying to suppress/hide a given library, they start by recombining the object-files which were used to make the shared library.  You might be able to accomplish this via partial linking, but I do not see a solution (since shared libraries and shared objects are not interchangeable).Further reading:Merge multiple .so shared libraries (says it will not work...)What is Partial Linking in GNU Linker?ld - The GNU linker