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 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.


Observe that C code (and C++) use a preprocessor, and some preprocessor parameters are passed in the compilation command (but not in C or C++ files), perhaps using GNUmake.

Look also into GNU autoconf.

Observe that some C or C++ files can be generated, e.g. by https://carburetta.com/

On Linux, you could use https://man7.org/linux/man-pages/man3/dlopen.3.html and generate dynamically C++ plugins, see https://arxiv.org/abs/1109.0779

You can also generate machine code at runtime with https://asmjit.com/ or https://www.gnu.org/software/lightning/ (this can improve runtime performance).

The preprocessor is inside GCC open source, so you are allowed to improve it (under GPL license).

C++20 has modules, and you could use that feature.

A possibility could be to develop or extend your (open source) GCC plugin. The old (unmaintained and obsolete) Bismon project could be relevant.
https://github.com/bstarynk/bismon

Look also into old HorizonEurope https://www.decoder-project.eu/

I tend to think that for a large C++ project (the size of https://gcc.gnu.org/ or https://libreoffice.org/ ....) your goal is practically impossible.

Without knowing how large your C++ project (e.g. what is the output of Wheeler's sloccount utility on it, see https://dwheeler.com/sloccount/ ...) we cannot help you.

It would be nice to understand what kind of project it is.

Most large projects follow domain specific coding rules (e.g. https://en.wikipedia.org/wiki/MISRA_C ...) and many do define and document their own coding rules.

In that case, developing your GCC plugin to check some of them might be useful.

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