Posting on this old thread in case anyone stumbles upon this in the future.. as it totally looks like the clangd team isn’t willing to work on proper support for this, it seems that workarounds is all we have..
After fighting with this myself for a long time, the best workaround I have found yet is the one described in https://www.frogtoss.com/labs/clangd-with-unity-builds.html.
Essentially, assuming unity.cpp is your main (only) translation unit that includes all other .cpp files PLUS any necessary headers etc, what you do is:
- Add
#pragma onceto the top of this file - Add
#include "unity.cpp"to the top of every other .cpp file - Profit!
What this does is, it leaves your unity build unaffected, since t…
Posting on this old thread in case anyone stumbles upon this in the future.. as it totally looks like the clangd team isn’t willing to work on proper support for this, it seems that workarounds is all we have..
After fighting with this myself for a long time, the best workaround I have found yet is the one described in https://www.frogtoss.com/labs/clangd-with-unity-builds.html.
Essentially, assuming unity.cpp is your main (only) translation unit that includes all other .cpp files PLUS any necessary headers etc, what you do is:
- Add
#pragma onceto the top of this file - Add
#include "unity.cpp"to the top of every other .cpp file - Profit!
What this does is, it leaves your unity build unaffected, since the circular include in each .cpp component will be ignored (due to the #pragma). However, assuming your clangd is configured in the typical manner to compile each of your .cpp files individually, each of these compilations should now succeed since each .cpp file includes everything it needs at the very top.
This is probably still not perfect but it’s miles better than the default clangd behaviour. I’m still testing out some kinks, my unity build is actually broken down per engine module, so there are definitely more complications there..
If anybody figures out a better system, I’d be super interested in hearing about it!