Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Include What you use"

I read about tool called "include-what-you-use" which can help clean superfluous includes from source code. I understood that there is a version for compiler LLVM(clang) and version for GCC.

My questions are:

  1. Why this tool is compiler-dependent and not "cross-platform" for compilers. Why from the beginning the creators of the tool didn't make it compiler-independent? Is it related to the special implementation it has or something like that?
  2. If I want to take a version of the tool compatible for LLVM and I want to make it compatible with GCC (since I'm working with GCC), what do I have to do for that?
like image 312
Or Shemesh Avatar asked Aug 06 '17 04:08

Or Shemesh


2 Answers

For the most part, Include-What-You-Use should be able to handle any valid C++ codebase, regardless of whether that codebase was written with gcc or clang in mind. I recently had the occasion to run Include-What-You-Use on a very large codebase that was usually compiled with gcc and it worked fine. So in that sense it is already compatible.

That said, it might not work perfectly. It's likely that some of the information it provides will be wrong, even if it's a clang codebase. So always verify the output manually.

like image 59
Flight Odyssey Avatar answered Oct 13 '22 23:10

Flight Odyssey


  1. why this tool is compiler-dependent and not "cross-platform" for compilers. Why from the beginning the creaters of the tool didn't make it compiler-independent ? is it related to the special implementation it has or something like that ?

Reason is simple, clang has is more modern fresh and has better modular architecture. As a result is is much easier to create tools using clang modules.

That is why clang was first which had address sanitizer and have more cool sanitizers. And this is why when someone creates new tool for C++ stars from clang.

  1. If i want to take a version of the tool compatible for llvm and i want to make it compatible with gcc(since i'm working with gcc). What i have to do for that ?

clang was created since Apple was not happy with gcc. So when it was written it supposed to be as much compatible with gcc as possible, since there was lots of code which was verified with gcc.

Since clang is mature now and provides new own features, there might be small differences with gcc (for example different bugs in implementations of new C++ standards), but in most common code there should be no problem.

IWYU should work without problems on both compilers. My coworker used it on large project build with 3 compilers (clang, gcc and VS) and it worked like a charm.

like image 44
Marek R Avatar answered Oct 14 '22 01:10

Marek R