Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clangd warnings on transitive includes #816

Closed
ferdymercury opened this issue Dec 13, 2022 · 1 comment · Fixed by #1008
Closed

clangd warnings on transitive includes #816

ferdymercury opened this issue Dec 13, 2022 · 1 comment · Fixed by #1008

Comments

@ferdymercury
Copy link
Contributor

ferdymercury commented Dec 13, 2022

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 ferdymercury changed the title clangd warnings clangd warnings on transitive includes Dec 13, 2022
@Spixmaster
Copy link

Spixmaster commented Jan 27, 2023

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.

phlptp added a commit that referenced this issue Mar 20, 2024
Added include-what-you-use pragmas to:
* let IWYU point users to the main include file CLI/CLI.hpp
* tell IWYU that CLI/CLI.hpp is the main exporting header.

This should fix #816

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Philip Top <phlptp@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants