Is there a way to compile source code with g++
, and have the compiler warn me if I have not included a file in another file where I should have?
For example, in a large project it is often quite easy to write some code in fileA
, which uses another function from fileC
(which contains the function declaration), but forget to add the include statement. Such an error can be hidden if fileA
also includes another file, fileB
, where fileB
includes fileC
.
This will then compile without error, however if the code is modified at a later date, and we remove the #include fileB.hpp
from fileA
, then compilation will fail, because we originally forgot to include fileC
many months ago!
Is there a compiler switch which will warn us about this problem? Similarly, is there the reverse switch, which will warn us when we #include
something which is unnecessary?