From: Ian Lance Taylor <iant@google.com>
To: Anthony Weston <tony.weston@veliosystems.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Statically linking in a static library
Date: Tue, 20 Dec 2011 05:38:00 -0000 [thread overview]
Message-ID: <mcrbor3ajlt.fsf@dhcp-172-18-216-180.mtv.corp.google.com> (raw)
In-Reply-To: <CAPOzOFNbFUwJE5r5vQ0-esQRYDMuUqOMPQ+C1-iwp7623GMO3g@mail.gmail.com> (Anthony Weston's message of "Mon, 19 Dec 2011 16:21:02 -0500")
Anthony Weston <tony.weston@veliosystems.com> writes:
> I'm having trouble with statically linking. I've created a static
> library that statically links to other static libraries. My hope by
> doing this was so other users would only need to include one static
> library when linking in their executable. However when I nm the
> created the static library all the references are unresolved. Is
> there an argument that will force the linker to resolve these symbols?
>
> Example:
>
> libA.a defines functionA.
> libB.a defines functionB.
>
> I create libC.a which statically links and uses both libA.a and libB.a.
>
> When running nm libC.a the results show that neither functionA nor
> functionB can be resolved so libA.a and libB.a also need to be
> statically linked into the final executable.
Yes, that is how Unix linkers work.
If you want the final program to be able to only link against a single
library, then you will need to incorporate libA.a and libB.a into
libC.a. E.g., do something along the lines of
ar x libA.a
ar x libB.a
ar rc libC.a *.o
Ian
next prev parent reply other threads:[~2011-12-20 5:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-19 21:21 Anthony Weston
2011-12-20 5:38 ` Ian Lance Taylor [this message]
2011-12-20 16:02 ` Joel Dice
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=mcrbor3ajlt.fsf@dhcp-172-18-216-180.mtv.corp.google.com \
--to=iant@google.com \
--cc=gcc-help@gcc.gnu.org \
--cc=tony.weston@veliosystems.com \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).