From: Shriramana Sharma <samjnaa@gmail.com>
To: Linux C Programming List <linux-c-programming@vger.kernel.org>
Subject: Way to leave-out unused functions while linking to a library
Date: Tue, 23 May 2006 14:43:32 +0530 [thread overview]
Message-ID: <200605231443.35393.samjnaa@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1185 bytes --]
I asked this question on this list some time back, IIRC -- how to leave-out
unused functions while linking to a library?
The normal behaviour is that if a library.c contains two functions fna() and
fnb() and main.c calls only fna(), compiling library.c and main.c and linking
to form an executable will result in the fnb() function getting included in
the final executable, though it is never used in the entire course of the
program.
So how to stop fnb() from getting linked in?
Over at the GNU GCC list, a good soul gave us the solution. Use -
-ffunction-sections -fdata-sections
as compiler options and
--gc-sections
as a linker option. If you are calling the linker indirectly via the compiler
gcc (i.e. if you are directly creating executables using gcc without a
separate call to ld) then give it the options:
-ffunction-sections -fdata-sections -Wl,--gc-sections
[exactly as it is, with the comma] so that the compiler passes the appropriate
option on to the linker. This method worked for me!
--
Tux #395953 resides at http://samvit.org
playing with KDE 3.51 on SUSE Linux 10.1
$ date [] CCE +2006-05-23 W21-2 UTC+0530
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
reply other threads:[~2006-05-23 9:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=200605231443.35393.samjnaa@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).