Re: How to identify unnecessary include header files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 2025-08-10 at 22:02 +0200, Jonathan Wakely wrote:
> 
> 
> On Sun, 10 Aug 2025, 20:28 Basile Starynkevitch, <basile@xxxxxxxxxxxxxxxxx> wrote:
> > On Sun, 2025-08-10 at 23:38 +0530, Rajeev Bansal via Gcc-help wrote:
> > > Hello,
> > > 
> > > I am working on a large C/C++ project compiled with GCC and am looking for
> > > ways to identify unnecessary header files. I'm wondering if there's a tool
> > > similar to `include-what-you-use` (IWYU) that can help with this
> > > information in gcc.
> > > 
> > > Any advice or recommendations would be greatly appreciated.
> > 
> > In addition of the previous reply, don't forget link time optimization and precompiled headers in GCC. Sometimes both are improving things.
> > 
> > Observe that even the optimization level is known (and used) in some Linux system header files.
> > (so your goal depend upon the compilation options)
> 
> 
>  how is this answer related to the question?!



Simply because a header file "gee.h" might contain

#if __OPTIMIZE__
#include "boo.h" /* which declare foo */
static inline int bar(int y) { return foo(y)+2; }
#else
int bar (int);
#endif 

Hence the set of included header files depend upon the optimization levels

(IIRC the Qt library might use similar tricks; in addition Qt is generating C++ code at build time)

Regards.

-- 
Basile STARYNKEVITCH                            <basile@xxxxxxxxxxxxxxxxx>
8 rue de la Faïencerie                       http://starynkevitch.net/Basile/  
92340 Bourg-la-Reine                         https://github.com/bstarynk
France                                https://github.com/RefPerSys/RefPerSys




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux