0

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.c
gcc -shared -Wl,-soname,libnew.so.1 -o libnew.so.1.0 *.o -L. -lold
ln -sf libnew.so.1.0 libnew.so.1
ln -sf libnew.so.1.0 libnew.so

For the executable :

#this does not work and needs -lold as well.
gcc -Wall main.c -L. -lnew -o prog

Is there anything missing? Thanks!

closed as unclear what you're asking by Julie Pelletier, G-Man, Rahul, GAD3R, Eric Renouf Sep 7 '16 at 10:47

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

What is missing is that your linker command

gcc -shared -Wl,-soname,libnew.so.1 -o libnew.so.1.0 *.o -L. -lold

does 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:

Not the answer you're looking for? Browse other questions tagged or ask your own question.