views:

259

answers:

3

Follow up of this question:

When I do include <iostream> .
It happens that it includes many files from /usr/include .A grep "\usr\include" over g++ -E prog.cpp counted to about 1260 entries ;).

Is their a way to control including various files?
Platform: Linux
G++ version: 4.2.4

+11  A: 

No, <iostream> includes them because it depends on them directly, or it's dependancies depend on them.

Ain't nothing you can do about it.

You can (depending on your compiler) limit the effect this has on compilation times by using Precompiled Headers

Binary Worrier
+2  A: 

You #include <iostream> when you need to use streams. That should define some things you need. How much activity it needs to do this is a quality of implementation issue. You could remove files from /usr/include, but that would break things.

I really doubt it's including 1260 files. Almost certainly most of those are duplicate entries that don't load anything but aren't pruned from the -E output.

David Thornley
+3  A: 

My suggestion is not to worry about how many files the compiler is including. Focus more on correctness, robustness, and schedule. If build time is a concern, get a faster machine, build overnight, go on a walk, or divide the code into smaller translation units. Translation units should be small enough to contain code that doesn't change often. Changes are EVIL.

The foundation of the build system is to compile only the few files that have changed. If your development process is functioning correctly, the build time will reside more and more in the linking phase as the project grows.

If the compile time is still lengthy, see if your compiler supports precompiled headers. Generally, this is method for the compiler to store all the declarations and definitions in a more efficient form.

Thomas Matthews