Why so many libraries compiled into basic sketch?

I turned on the verbose option for compiling on one of my sketches and found warnings coming up for libraries that I had not used.

To further test, I compiled the example Blink sketch included with arduino IDE (1.0.3) with verbose output on.
The first part of the listing is below.

Why are files for IP adddressing, wiring, printing, math, tone, etc compiling into the very basic blink sketch?

avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=103 -I/home/fred/Development/arduino-1.0.3/hardware/arduino/cores/arduino -I/home/gggg/Development/arduino-1.0.3/hardware/arduino/variants/mega /tmp/build4310607114410777950.tmp/Blink.cpp -o /tmp/build4310607114410777950.tmp/Blink.cpp.o 
  Using previously compiled: /tmp/build4310607114410777950.tmp/wiring_digital.c.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/wiring.c.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/wiring_shift.c.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/wiring_analog.c.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/WInterrupts.c.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/wiring_pulse.c.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/Print.cpp.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/IPAddress.cpp.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/WMath.cpp.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/new.cpp.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/CDC.cpp.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/Tone.cpp.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/main.cpp.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/WString.cpp.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/HID.cpp.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/Stream.cpp.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/USBCore.cpp.o
  Using previously compiled: /tmp/build4310607114410777950.tmp/HardwareSerial.cpp.o

The output is not telling you that is it compiling those functions. It is telling you that it has found that those functions do not need to be compiled, because the object files are up to date.

Just because something is compiled, or determined to not need compiling, does not mean that the linker will include all the object files in the resulting hex file. Only parts of object files are used, and only those parts that are needed.

Thanks Paul.

The output is not telling you that is it compiling those functions.

When I remove the temporary files and compile the blink sketch again I get (amongst others) the lines:

avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega2560 -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=103 -I/home/fred/Development/arduino-1.0.3/hardware/arduino/cores/arduino -I/home/fred/Development/arduino-1.0.3/hardware/arduino/variants/mega /home/fred/Development/arduino-1.0.3/hardware/arduino/cores/arduino/IPAddress.cpp -o /tmp/build4310607114410777950.tmp/IPAddress.cpp.o 
In file included from /home/fred/Development/arduino-1.0.3/hardware/arduino/cores/arduino/IPAddress.cpp:3:0:
/home/fred/Development/arduino-1.0.3/hardware/arduino/cores/arduino/IPAddress.h: In member function ‘IPAddress::operator uint32_t()’:
/home/fred/Development/arduino-1.0.3/hardware/arduino/cores/arduino/IPAddress.h:51:55: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/home/fred/Development/arduino-1.0.3/hardware/arduino/cores/arduino/IPAddress.h: In member function ‘bool IPAddress::operator==(const IPAddress&)’:
/home/fred/Development/arduino-1.0.3/hardware/arduino/cores/arduino/IPAddress.h:52:75: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/home/fred/Development/arduino-1.0.3/hardware/arduino/cores/arduino/IPAddress.h:52:108: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

Ignoring the warnings, it seems that the the IPAddress.h, and most likely IPAddress.c, are being compiled.
Compilers are often promoted rated on their speed of compilation, therefore it seems odd to me that a compiler would waste time compiling libraries which it is not going to use.

Only parts of object files are used, and only those parts that are needed.

In the past you have shown some knowledge of the networking with Arduino. Do you know which parts of the IPAddress.h or IPAddress.c would be used in the Blink example? (Or wiring, print, stream, tone for that matter).

Compilers are often promoted rated on their speed of compilation, therefore it seems odd to me that a compiler would waste time compiling libraries which it is not going to use.

It only does that if you delete files it needs.

Do you know which parts of the IPAddress.h or IPAddress.c would be used in the Blink example?

None of them.

(Or wiring, print, stream, tone for that matter).

HardwareSerial derives from Stream which derives from Print. An instance of HardwareSerial is created, whether you actually use it, or not. Wiring.c contains a lot of the Arduino-specific functions, like pinMode() and digitalWrite(), so those functions are needed for blinking an LED.