Compiler Optimization to eliminate unused functions

I’m posting this on the 3Pi forum as that’s the platform that I’m using. Read some other posts about setting the option flags on the GCC, but I left even more confused - too many options, and I don’t really understand how most of them apply to my issue. Namely, I am trying to avoid bloated code.

I was looking at code space (bytes used) and saw that some really simple programs were quite large. Decided to test a simple program that just turned on the red LED. Only used the red_led(1) command; however the .lss file showed that the green_led, left_led , right_led as well as a couple cryptic Orangutan LED routines were in the final code.

Is there a simple way to compile source code to extract only the the routines that are actually called?

Hello,

We have a discussion of options here. Specifically, you want the -Wl,-gc-sections linker option.

-Paul

Thanks, for steering me in the right direction! I’ll give the -Wl, -gc option a try.