linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* can't understand linking behaviour
@ 2007-05-27 14:50 Shriramana Sharma
  2007-05-28 23:29 ` Glynn Clements
  0 siblings, 1 reply; 4+ messages in thread
From: Shriramana Sharma @ 2007-05-27 14:50 UTC (permalink / raw)
  To: Linux C Programming List

[-- Attachment #1: Type: text/plain, Size: 1422 bytes --]

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 -lb

My 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 #2: shlib-test.tar.gz --]
[-- Type: application/gzip, Size: 421 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-06-20 14:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-27 14:50 can't understand linking behaviour Shriramana Sharma
2007-05-28 23:29 ` Glynn Clements
2007-06-15  4:20   ` Shriramana Sharma
2007-06-20 14:39     ` Pedro de Medeiros

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).