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

headers from pch are not recognized inside project #2040

Closed
dylsonowski opened this issue May 15, 2024 · 8 comments
Closed

headers from pch are not recognized inside project #2040

dylsonowski opened this issue May 15, 2024 · 8 comments

Comments

@dylsonowski
Copy link

As I mentioned in #2034 (comment) I have big problem with pch in my project. As it was suggested, adding Expect.hpp to pch file was my mistake so I removed it but the error still occur. The same problem is present in Matrix.hpp.

image

Strange thing that I realized is the fact that there are no such errors with internal include files added to pch. The problem seems to occur only for std library

@HighCommander4
Copy link

The workaround I suggested in #2034 was:

A workaround would be to include palepch.hpp from Expect.hpp.

i.e. to add #include "palepch.hpp" to Expect.hpp, to make Expect.hpp self-contained.

The same applies to Matrix.hpp, that file is also not currently (assuming we're talking about the version here) self-contained, and adding #include "palepch.hpp" to it would make it self-contained and satsify clangd.

@dylsonowski
Copy link
Author

Okey, and why this workaround needs to be performed? Isn't it correct use of pch to include them only in .cpp inplementation of the header file?

@HighCommander4
Copy link

Like I've said in the other issue, not supporting files which are not self-contained is a known limitation of clangd, tracked in #45.

@dylsonowski
Copy link
Author

So basically, I can't use clangd with pch?

@HighCommander4
Copy link

Adding #include "palepch.hpp" to headers like Matrix.hpp and Expect.hpp should not interfere with your ability to use PCH during compilation and benefit from any resulting compile-time speedup.

When the compiler encounters the #include "palepch.hpp" in a header like Matrix.hpp while translating a source file, it will just ignore its contents since it has already loaded them as a PCH.

@dylsonowski
Copy link
Author

Ok, the last question. If I get it wright, I have to include my pch file in all header files that needs to use standard library?

@HighCommander4
Copy link

HighCommander4 commented May 19, 2024

I have to include my pch file in all header files that needs to use standard library?

The general principle is, until #45 is implemented, any file that you open for editing with clangd needs to be self-contained. That means that for any symbol used in the file (for example, std::cout), the header which defines that symbol (for example, <iostream>) needs to be included, directly or indirectly, from that file.

In this example project, including the PCH header in headers like Expect.hpp is an easy way to accomplish that. But alternatively, you could include things like <iostream> directly in a header like Expect.hpp as well.

@dylsonowski
Copy link
Author

Ok, thank you for help

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

No branches or pull requests

2 participants