Get compile_commands.json

I can confirm this works on my side, although I also have some problems (mentioned down below).

Here’s how I make it happen:

  1. Make sure your project is actually built with the build tool. Without it you’ll get warnings due to missing UHT-generated code.
  2. Generate compile_commands.json with Build.sh. In my case my project is called Tlob, so I use TlobEditor module, Linux target (for Windows, it’s Win64), and DebugGame configuration (default would be Development), but you gotta adjust those for you project and directories (just make sure to use absolute directories):
"/home/korn/UnrealEngine/Engine/Build/BatchFiles/Linux/Build.sh" \
	-mode=GenerateClangDatabase \
	-project=/home/korn/Tlob/Tlob.uproject \
	TlobEditor \
	Linux \
	DebugGame \
;
  1. Now, the generated compile_commands.json is located under UnrealEngine’s root directory. You either have to copy or link it into your project’s root directory, but do NOT delete the original file. For example, I do following symbolic link:
ln \
	-sfv \
	~/UnrealEngine/compile_commands.json \
	~/Tlob/compile_commands.json \
;
  1. You may need to restart clangd (or other language server that you use).

Now, the tricky part - problems:

  • Not every clangd version seems to work on my side. I suspect this is because my system-wide headers are clashing with the engine’s headers from its own toolchain. For now I use clangd that comes from mason.nvim package manager, but this is only available for Neovim. Not sure, how someone with Emacs, Vim or VSCode would solve this. Perhaps, you could try sandboxing clangd or passing some additional flags to it.
  • Generation of compile_commands.json is NOT incremental, and takes around 45sec on my machine. To be honest, this is a big issue for me - I add/remove/change one include and I gotta regenerate everything. I’m looking for the solution on this one.
  • Just like someone already mentioned, compile commands doesn’t seem to include Engine’s prelude CoreMinimal.h. I personally don’t like using it, but this is in fact annoying.
  • Indexing takes a lot of time and resources. If you have less than 32gigs of RAM, you may OOM while doing something intensive with the Engine.
  • Seems like this Build tool mode is not well tested and buggy (at least on Linux). I suspect, Epic made it only to support people on MacOSX and we kinda have to deal with it…

Proof it works:



1 Like