CLI11 icon indicating copy to clipboard operation
CLI11 copied to clipboard

clangd warnings on transitive includes

Open ferdymercury opened this issue 3 years ago • 1 comments

In the README, it is recommended to include the following three headers in your application:

#include "CLI/App.hpp" #include "CLI/Formatter.hpp" #include "CLI/Config.hpp"

This works well, with the exception that clangd raises warning:

image

If I remove the two headers below, then I get a compilation error:

/usr/bin/ld: CMakeFiles/bth.dir/bth.cpp.o: warning: relocation against `_ZTVN3CLI9FormatterE' in read-only section `.text._ZN3CLI9FormatterC2Ev[_ZN3CLI9FormatterC5Ev]'
/usr/bin/ld: CMakeFiles/bth.dir/bth.cpp.o: in function `CLI::ConfigBase::ConfigBase()':
/opt/CLI11/include/CLI/ConfigFwd.hpp:81: undefined reference to `vtable for CLI::ConfigBase'
/usr/bin/ld: CMakeFiles/bth.dir/bth.cpp.o: in function `CLI::Formatter::Formatter()':
/opt/CLI11/include/CLI/FormatterFwd.hpp:120: undefined reference to `vtable for CLI::Formatter'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status

It would be nice if the warnings raised by clangd were suppressed via IWYU pragma comments on the CLI11 header files: https://clangd.llvm.org/guides/include-cleaner#scenarios-and-solutions

If I add #include "CLI/CLI.hpp" instead of the three above, I get a similar warning, because of the transitive includes.

ferdymercury avatar Dec 13 '22 09:12 ferdymercury

I can confirm the issue. include-what-you-use also suggests removing those for me but when you do you get undefined reference to vtable.

Spixmaster avatar Jan 27 '23 14:01 Spixmaster