3 ms·
What I've always wanted is to write C++ code and have the minimal set of necessary includes needed to compile my code automatically added [edit: I should have s
by ur-whale 6y ago
What I've always wanted is to write C++ code and have the minimal set of necessary includes needed to compile my code automatically added [edit: I should have said "managed"] by the IDE.
How close can this tool get to that goal?
- burntoutfire 6y agoI've just Googled the same question. The answers seem to glorify the suffering of writing C++ and suggest that the inquirer would perhaps be better off with switching to Java... Sounds like a case of Stockholm syndrome to me. Anyway, I'm a beginner in C/C++ world and the most convincing solution I've found to use in my personal project is the Single Compilation Unit approach (https://en.wikipedia.org/wiki/Single_Compilation_Unit https://en.wikipedia.org/wiki/Single_Compilation_Unit). It is exemplified in the Handmade Hero github repository (which I'm afraid is available for paying users only). Essentially, the whole program is divided into modules, each within its own single cpp file. The modules are then all included in the SCU, which is the only file passed to the compiler. There can be no circular dependencies between modules (as then, there would be no order of including them in SCU which would work). In HH's case, there seems to be an absolutely minimal number and volume of headers and they only define data structures, never declare functions.
- aflag 6y agoCLion is capable of adding missing includes, I'm not sure if it tells you about unused ones. They have a free trial, may be worth a try.
- alexhutcheson 6y agoclang-include-fixer is the better tool for that: https://clang.llvm.org/extra/clang-include-fixer.html https://clang.llvm.org/extra/clang-include-fixer.html