Compiler optimisation

Apologies if this is the wrong section, have browsed the faqs and forum before posting this question.
When a library is imported for compilation, does the compiler use the whole library or just the statements and procedures called in the program.

Just what's called.

Thank you for replying so quickly.

CrossRoads:
Just what's called.

Not exactly.
For the most part this is correct; however,
If the library code uses interrupts, then the ISR routines will always be pulled in
and then any routines or data that those ISRs call will pulled in as well.

You can see this if you say include <Wire.h> (the wire library) and then not use it.
Your code will get larger even though you never used the Wire library.

Oh and out of correctness, it is actually a linker optimization.
The compiler put it all in, then the linker recognized it wasn't be used so it
strips it out.

--- bill

So it makes no sense to strip down a library if you don't need most of the functions?

I was thinking of the TVout library. All the graphics are not needed.
Hoping to get more characters on the screen.

steinie44:
So it makes no sense to strip down a library if you don't need most of the functions?

I was thinking of the TVout library. All the graphics are not needed.
Hoping to get more characters on the screen.

Correct.
The IDE sets a compiler option to put each function and data variable/object into its own section.
It also sets a linker option to tell the linker to look for a reference to each section.
If it doesn't see a reference to a section it removes the section,
which removes the unused/unreferenced code/data.

If you turn on the verbose mode in the IDE
[File]->[Preferences]
and then check
Show verbose output during: [] compilation

you will see the option to the compiler:

-fdata-sections -ffunction-sections

and to the linker:

-Wl,--gc-sections

--- bill