* Way to leave-out unused functions while linking to a library
@ 2006-05-23 9:13 Shriramana Sharma
0 siblings, 0 replies; only message in thread
From: Shriramana Sharma @ 2006-05-23 9:13 UTC (permalink / raw)
To: Linux C Programming List
[-- 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 --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-05-23 9:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-23 9:13 Way to leave-out unused functions while linking to a library Shriramana Sharma
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).