linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shriramana Sharma <samjnaa@gmail.com>
To: Linux C Programming List <linux-c-programming@vger.kernel.org>
Subject: can't understand linking behaviour
Date: Sun, 27 May 2007 20:20:31 +0530	[thread overview]
Message-ID: <46599AB7.1010701@gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2007-05-27 14:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-27 14:50 Shriramana Sharma [this message]
2007-05-28 23:29 ` can't understand linking behaviour Glynn Clements
2007-06-15  4:20   ` Shriramana Sharma
2007-06-20 14:39     ` Pedro de Medeiros

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46599AB7.1010701@gmail.com \
    --to=samjnaa@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).