unreal-clangd
unreal-clangd copied to clipboard
clang compilation errors
lots of errors in the clangd output tab:
I[13:53:57.290] Failed to compile /home/florian/lg/unreal/UnrealEngine/Engine/Source/ThirdParty/libSampleRate/Private/src_sinc.cpp, index may be incomplete
I[13:53:57.302] Failed to compile /home/florian/lg/unreal/UnrealEngine/Engine/Source/Runtime/SlateCore/Private/Rendering/SlateVectorGraphicsCache.cpp, index may be incomplete
I[13:53:57.397] Failed to compile /home/florian/lg/unreal/UnrealEngine/Engine/Plugins/Experimental/PlatformCrypto/Source/PlatformCryptoOpenSSL/Private/PlatformCryptoOpenSSL.cpp, index may be incomplete
I[13:53:57.557] Failed to compile /home/florian/lg/unreal/UnrealEngine/Engine/Plugins/Experimental/PythonScriptPlugin/Source/PythonScriptPlugin/Private/PyConversion.cpp, index may be incomplete
I[13:53:57.608] Failed to compile /home/florian/lg/unreal/UnrealEngine/Engine/Source/Runtime/TimeManagement/Private/TimeManagementModule.cpp, index may be incomplete
Ubuntu 23.10, unreal engine built from git, /usr/bin/clangd (16)
I'll take a look!
Just know that the Unreal source doesn't have a .clangd. If you try to look at a file from the Unreal source it'll get all the includes/compile flags from a random file from your project. It may or may not work.
That's one of the features that on the backburner. I would need to figure out how to create a compile_commands.json for the Unreal source.
I tested 5.3.2 full source with the FPS template. I did get the 'Failed to compile' on some project files. I remembered that the FPS template doesn't adhere to IWYU. After adding a few missing includes, to some project cpp files, the messages went away. When I removed the includes the messages reappeared. Full source project files 'seem' to work fine.
It's just that any files in the Unreal directory most likely won't work when opened currently.
I do plan to attempt to fix this.
is there a way to see compilation errors from clangd? that might help us in fixing the flags
Nope, not if you're looking at a Unreal Source file since this extension doesn't support that but it can support it.(see next post after this).
You can check to see if it's one of your project's source files that's causing it by opening up every one of your project's source files and seeing if clangd errors occur in your files.
You can do this easily with this VSCode extension that opens every file in a directory(can do this recursively too).
Be Careful if you have a lot of files. Do this by subdirectory instead.
Extension is called:
Now when I right click on a folder I get these options:
This is the FPS Template so I can just choose 'Open All Folder Files'. I did this on the project's Source/ProjectName folder which doesn't have subfolders.
When you open all these files, clangd will start compiling all of them so it may take awhile depending on your computer and how many files you have open.
Even though this project compiles correctly, clangd sees an error in one of the files. This is because clangd adheres strictly to IWYU which Epic says is the correct way for Unreal Projects.
This file is missing an include. Once it's added the error goes away.
UE5 Source
I've actually created my clangd config incorrectly if we are going to have a separate compile_commands.json or compile_flags.txt for the UE5 source code.
In your *.code-workspace you'll need to comment out or remove this:
Now move it to your .clangd file with the new CompilationDatabase under CompileFlags category:
CompileFlags:
CompilationDatabase: e:\\Users\\ME\\Documents\\Unreal Projects\\clangd_5_3_0\\.vscode\\unreal-clangd
Now we can add a .clangd file to the E:\Program Files\Epic Games\UE_5.3\Engine directory:
---
CompileFlags:
CompilationDatabase: E:/Program Files/Epic Games/UE_5.3/Engine
Add:
- -D__UE5_CLANGD_FILE_TEST
And I added a compile_flags.txt for testing which just has this line:
-D__CLANGD_COMPILE_FLAGS_TEST__
Now I open a random Unreal source file and this is what clangd shows(just to know the clangd files are being used)
I[21:59:21.945] ASTWorker building file e:\Program Files\Epic Games\UE_5.3\Engine\Source\Runtime\AdvancedWidgets\Private\Components\RadialSlider.cpp version 1 with command
[E:/Program Files/Epic Games/UE_5.3/Engine]
"c:\\Program Files\\LLVM\\bin\\clang-tool" -D__CLANGD_COMPILE_FLAGS_TEST__ -D__UE5_CLANGD_FILE_TEST "-resource-dir=c:\\Program Files\\LLVM\\lib\\clang\\16" -- "e:\\Program Files\\Epic Games\\UE_5.3\\Engine\\Source\\Runtime\\AdvancedWidgets\\Private\\Components\\RadialSlider.cpp"
You can see that the two defines show up.
Now with this you can somehow create a compile_commands.json or a universal compile_flags.txt for the Unreal source.
You can have mulitple .clangd files that point to different compile_command.json directories as well.
This allows you to configure plugins differently than the Unreal Source. Of course if you can create a universal file that works everywhere then that would be easier.
I will try to tackle this myself but I'm working on something else at the moment.