1

It seems that often I find that my code when moving either from one linux installation to another or from one unix to another, I find that I've missed including certain header files.

This tends to become annoying when you give the source to someone else expecting them to be able to compile it just fine, only for it to fail because of missing header file includes.

Are there any static analysis tools that can detect headers that should be explicitly included where they're currently seem to be implicitly included? Is there some way to disable this implicit inclusion of header files?

Also I'd like to detect header files that included and may have become redundant through code changes, and are no longer required.

jww
  • 97,681
  • 90
  • 411
  • 885
goji
  • 6,911
  • 3
  • 42
  • 59
  • I know of no such tools, but you could use something like [autoconf](http://www.gnu.org/software/autoconf/) to help you detect what header files are available on the system the application is being built on. Then you can receive "bugs" about missing header files on one system, and you just add a check for that header file in the configure script, and a conditional include in your source, and it will work on all platforms that need that specific header file. – Some programmer dude Jun 21 '12 at 07:20
  • Also, for POSIX function you can check the [official reference](http://pubs.opengroup.org/onlinepubs/007904975/) for the header files needed for specific functions. – Some programmer dude Jun 21 '12 at 07:22
  • Can you, please clarify what you mean under "implicitly included"? How are planning to deal with #includes that are under #ifdefs? Do you want full list of include files for all possible conditional compilation key combinations? As an example of similar analysis, you can take a look at building list of all conditional compilation keys that are used in the project: http://cdsan/Samp_CondParams.php – Kirill Kobelev Jun 23 '12 at 05:40
  • This question (http://stackoverflow.com/questions/1301850/tools-to-find-included-headers-which-are-unused) covers the final part of your question. – Richard Corden Aug 02 '12 at 18:53

2 Answers2

2

There is a google project called Include-What-You-Use that might be helpfull. But still it is very complicated to get it done right. And i'm not aware of any other tool that does this.

RedX
  • 14,749
  • 1
  • 53
  • 76
2

I have used checkheaders with some success. Development seems to have slowed down some in the last year, but it is still usable. Probably it's best to use the trunk version.

Benjamin Bannier
  • 55,163
  • 11
  • 60
  • 80