> -----Original Message----- > From: > [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > org] On Behalf Of Joerg Desch > Sent: Monday, February 18, 2008 7:25 AM > To: [email protected] > Subject: [avr-gcc-list] how to remove unused code? > > I'm trying to use the OSS library "libvisca" for controlling > a SONY camera. The port seems to compile, but the resulting > binary is ways to large. I only need some of the functions, > but the linker don't remove the unused stuff. > > Isn't the linker smart enough for that? > > libvisca comes as one big C file. Is this the problem?
Yes. Because then it is not truly a "library" per the definition. > I'm using the WinAVR Makefile Template... > You can enable the toolchain to remove unused code by adding these flags: CFLAGS += -ffunction-sections This tells the compiler to put each function in its own section. This must be used for all *compile* command lines, hence added to the CFLAGS variable. LDFLAGS += -Wl,-gc-sections This tells GCC to send the -gc-sections flag to the linker (via -Wl). The -gc-sections flag tells the linker to "garbage collect" (remove) unused sections. Since all functions are now in their own individual section, this has the effect of removing unused functions. This flag is a linker flag, so it is set in the LDFLAGS variable. HTH, Eric Weddington _______________________________________________ AVR-GCC-list mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
