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:
pgp0twOwt73fG.pgp
Description: PGP signature