Q:Only include referenced functions?

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using the latest WinAVR GCC, and want to minimize my program space usage.

I have files with many functions, but I would like it if the linker wouldn't link in those functions to which nobody refers.

So if I have a foo.c which defines:

function_1
function_2
function_3

and my main.c only calls function_2, I'd like it if the linker would just not include function_1 and function_3.

I thought if I put the module foo.c into a library, and then linked against that library, it would only pull in function_2. But it appears to grab function_1 and function_3.

Is there a way to do what I want to do?

In my case I have a uart.c which defines a lot of different uart functions (like printing a float, printing a U16, etc.) I don't use many of them, but they all get linked in and take up FLASH space.

Cheers,

Steven

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Steven!
If GCC compiler has "Make library module" option (IAR has) You have to set this option. But if the compiler hasn't such option You have to split Your module into some functions and include them in library separately from each other.
Regards!

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As Vlad wrote you should split your source into separate files and build library from them.
Look at the UART library for examples.

Regards,