Linux rdm compile_commands.json

Hey, i am using rdm (with emacs) for my game development. rdm requires a compile_commands.json file which is a file that contains all the the compile commands for the code. I am trying to create one for my game code and for UE4 engine code. usually to generate the compile_commands.json we run “bear” on the compile program, bear expect that the output of the compilation program to be with verbose with all of the command to compile the code but i cant get this from the game compilation.
Is there a way to generate compile_commands.json? Or somehow add --verbose to the clang command?

This was added to UBT in 4.24, the magic incantation is:

 UnrealBuildTool.exe -mode=GenerateClangDatabase -project="YourProject.uproject" -game -engine ProjectName Development Win64 

i.e., add -mode=GenerateClangDatabase to a normal UBT command for your project. The only documentation of this I see is in the 4.24 Release Notes which also mentions a -Filter parameter.

Thank you. I can confirm I have successfully set it up and managed to run it successfully using the following command in powershell: & ‘C:\Program Files\Epic Games\UE_4.24\Engine\Binaries\DotNET\UnrealBuildTool.exe’ -mode=GenerateClangDatabase -project=“ProjectName.uproject” ProjectName Development Win64". This basically created a “compile_commands.json” file in “C:\Program Files\Epic Games\UE_4.24”.

I do all development on Vim so I am trying to use the ccls language server (which uses clangd) to be able to read from the generated compile_commands.json file. The core development is done in WSL Linux (Ubuntu 18), and hence it’s required for the file to be translated such that it can be read with Linux paths namely as the output generated by UnityBuildTool is using Windows paths. It seems that just using this open source python function was able to do the job wsl-compile-commands-converter/ at master · Kazhuu/wsl-compile-commands-converter · GitHub

I am currently still getting syntax error highlights in the file, even though the “go-to-reference” shortcuts still work. For example, I get errors for the object inheritance “Super” reference, however if I hit go-to-reference it still takes me to the respective source code. Have you been able to resolve this?

Hi. Can we generate the clang database on Linux and use clangd there? I would like to develop from emacs(spacemacs) on linux if possible.

Same situation here, not able to use -mode=GenerateClangDatabase it complaints about not finding clang, which is insatlled.

Yeah, ‘-mode=GenerateClangDatabase’ currently doesn’t work on Linux at the moment.

There’s was a pull-request which adds Linux support, but the author has stopped maintaining it.

The author claims that the VSCode project generator creates a usable compile_commands.json, but I can’t figure out how to make that work with ccls.

I am an emacs user and am trying to get emacs and clangd work with Unreal Engine Code. I have used UBT to generate the compile-database.
I run emacs and clangd in Windows Subsystem for Linux (WSL). Though clangd could parse the compile-database file correctly, it seems that it still need something else to compile the code. In the log of clangd I could find something like this:

I[22:35:10.483] Indexed /mnt/d/workplace/UnrealEngine/Engine/Source/Runtime/RenderCore/Private/RayTracingInstanceCopyShader.cpp (23607 symbols, 77274 refs, 469 files)
I[22:35:10.490] Failed to compile /mnt/d/workplace/UnrealEngine/Engine/Source/Runtime/RenderCore/Private/RayTracingInstanceCopyShader.cpp, index may be incomplete

As a result, I cannot take advantage of the full functionality clangd provides. It can’t find definitions of some symbol. To be more specific, clangd could not find definitions for most of the symbols in a header file. It works for symbols in some simple structs at the beginning of the header. However, it failed to find definitions for everything else in the file. For example, in the file PlayerCameraManager.h, clangd could find definitions for the struct FMinimalViewInfo, but it could not find definition for AActor which appears as the base class of APlayerCameraManager.

I am not sure this is a problem of the compile-database file which is produced by UBT, or it is a problem of clangd. I hope someone in the Unreal community could help me with that since I have no knowledge about programming language, compiler and Language Server Protocol (LSP), but I really want to combine these powerful tools: emacs, LSP, clangd and Unreal Engine.

1 Like