Consider: main.c calls function firstcall() a.c defines function firstcall() which calls secondcall() b.c defines function secondcall() To build the executable main, I need to do: gcc -fPIC -c a.c gcc -fPIC -shared -o liba.so a.o gcc -fPIC -c b.c gcc -fPIC -shared -o libb.so b.o gcc -o main main.c -L. -la -lbMy question is, why does not the creation of liba.so require the presence of and linking against libb.so, seeing as a.o contains firstcall() which calls secondcall() present only in libb.so?
The gcc command building liba.so does not use -c which would prevent the linker from being called. So if the linker is called then it should require the presence of and linking to libb.so to resolve the reference to the external function secondcall(). But this does not happen.
What does happen is that I am supposed to specify at the point of building the *executable* not only the libraries that the executable depends on, but also the libraries that *those* libraries depend on, as well as, presumably, any third-level, fourth-level and upto n-th level dependencies.
This seems highly counter-intuitive. Why would the linker require *only* at *executable* build-time the libraries, and the whole dependency *tree* at that, to be specified? Why does it not need at each level of build of an executable or library its and only its own dependencies?
Thanks as always, in advance, Shriramana Sharma.
Attachment:
shlib-test.tar.gz
Description: application/gzip