# Get compile\_commands.json

**URL:** <https://forums.unrealengine.com/t/get-compile-commands-json/433389>\
**Category:** Platform & Builds\
**Tags:** compiling, engine-compile, Linux, unreal-engine, UE4, question\
**Created:** [September 7, 2018, 5:52pm UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389 "2018-09-07T17:52:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_5be014f9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5be014f9](https://forums.unrealengine.com/u/anonymous_user_5be014f9)\
**Post date:** [September 7, 2018, 5:52pm UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/1 "2018-09-07T17:52:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TBBle](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tbble/32/996112_2.png) [@TBBle](https://forums.unrealengine.com/u/TBBle)\
**Post date:** [November 27, 2018, 12:35am UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/2 "2018-11-27T00:35:31Z")

</div>

[Bear](https://github.com/rizsotto/Bear) doesn’t depend on the output of the build tool, it depends on being loaded into the build process and intercepting the `exec` calls to the compiler.

---

<div class="post-metadata">

**Author:** ![TBBle](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tbble/32/996112_2.png) [@TBBle](https://forums.unrealengine.com/u/TBBle)\
**Post date:** [November 27, 2018, 1:57am UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/3 "2018-11-27T01:57:36Z")

</div>

The first two steps on [Sourcetrail with Unreal Engine 4 - a quick primer](https://ttimo.typepad.com/blog/2018/09/sourcetrail-with-unreal-engine-4-a-quick-primer.html) suggest a working approach, until native support for [JSON Compilation Database](https://clang.llvm.org/docs/JSONCompilationDatabase.html) is added to the Unreal Build Tool.

_Quoting the steps:_

1. Install a patched version of Bear from [GitHub - TTimo/Bear at ttimo](https://github.com/TTimo/Bear/tree/ttimo) (note: ttimo branch)
2. From a clean UE4 tree, capture a compilation database:  
`bear -o ./UE4Game.json ./Engine/Build/BatchFiles/Linux/Build.sh UE4Game Linux Development -disableunity -nopch`

He points out two issues that currently block [Bear](https://github.com/rizsotto/Bear) from capturing UE4 builds correctly:

- [Issue 194: deadlocks](https://github.com/rizsotto/Bear/issues/194); and
- [Pull request 224: Do not skip over -cc1 compilations](https://github.com/rizsotto/Bear/pull/224).

---

<div class="post-metadata">

**Author:** ![TBBle](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tbble/32/996112_2.png) [@TBBle](https://forums.unrealengine.com/u/TBBle)\
**Post date:** [May 4, 2020, 1:09am UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/4 "2020-05-04T01:09:14Z")

</div>

As of UE 4.24, there is a new mode for UBT: `GenerateClangDatabase` to do this.

The only documentation I’m aware of is in the [4.24 Release Notes](https://docs.unrealengine.com/en-US/Support/Builds/ReleaseNotes/4_24/index.html), and there it mentions two new things to UBT: `-mode=GenerateClangDatabase` to enable `compile_commands.json` generation and `-Filter=` to limit the files included.

That will generate a compile\_commands.json instead of actually compiling, similar to how the Intellisense code-gen works. I haven’t looked, but I imagine it’s basically the same code-path as used to generate Intellisense.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f8ba459f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f8ba459f](https://forums.unrealengine.com/u/anonymous_user_f8ba459f)\
**Post date:** [October 28, 2020, 10:22am UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/5 "2020-10-28T10:22:19Z")

</div>

This made my day, I really don’t want to develop using Windows… But I cannot manage to make it work. I haven’t been able to generate, compile\_commands.json. I’m not sure if I’m using the UBT tool correctly. Could you share the steps if you have managed to generate the compile\_commands.json? Thanks for sharing!

---

<div class="post-metadata">

**Author:** ![TBBle](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tbble/32/996112_2.png) [@TBBle](https://forums.unrealengine.com/u/TBBle)\
**Post date:** [October 28, 2020, 10:33pm UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/6 "2020-10-28T22:33:22Z")

</div>

Notes from the time give this as the command to run:

```auto
C:\unrealengine\Engine\Binaries\DotNET\UnrealBuildTool.exe -mode=GenerateClangDatabase -project="Path\To\My\Project.uproject" -game -engine Target Development Win64

```

and it will generate _C:\unrealengine\compile\_commands.json_.

That was with a full-source engine from GitHub, it should work similarly with an installed engine.

To be clear, I haven’t done this in a while, this is just going off notes we took at the time we found this.

---

<div class="post-metadata">

**Author:** ![TBBle](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tbble/32/996112_2.png) [@TBBle](https://forums.unrealengine.com/u/TBBle)\
**Post date:** [October 28, 2020, 10:34pm UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/7 "2020-10-28T22:34:32Z")

</div>

One issue we noted in our testing (UE 4.24.3) is that the compile\_commands.json generated doesn’t include the _Intermediate_ directories where the _.generated.h_ files live, so it didn’t actually _work_ for me in the end. I’m not sure if that’s been fixed since.

---

<div class="post-metadata">

**Author:** ![Kakus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kakus](https://forums.unrealengine.com/u/Kakus)\
**Post date:** [December 23, 2020, 7:31pm UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/8 "2020-12-23T19:31:37Z")

</div>

I managed to add generated includes in the compile\_commands although you have to modify the UnrealBuildTool itself. I’ve done in on 4.26.0  
The file to modify UE\_4.26\Engine\Source\Programs\UnrealBuildTool\Modes\GenerateClangDatabase.cs line 123, I’ve added line below

```
CommandBuilder.AppendFormat(" -I\"{0}\"", Module.GeneratedCodeDirectory);
```

---

<div class="post-metadata">

**Author:** ![officernickwilde](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/officernickwilde/32/547477_2.png) [@officernickwilde](https://forums.unrealengine.com/u/officernickwilde)\
**Post date:** [February 4, 2021, 12:01pm UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/9 "2021-02-04T12:01:28Z")

</div>

Hi everyone, sorry for waking up an old thread. Ive been trying to get LLVM’s language server Clangd working with Unreal Engine, using this cmd:

& ‘D:\Program Files (x86)\Epic Games\UE\_4.26\Engine\Binaries\DotNET\UnrealBuildTool.exe’ Development Win64 BullCowGame “C:\Users\Oliver\Documents\Unreal Projects\BullCowGame-starter-kit\BullCowGame.uproject” -mode=GenerateClangDatabase

I was able to generate a compile\_commands.json in my engine directory. However this file doesnt seem to mention all includes necessary. Like CoreMinimal.h for instance is missing and many includes that in fact are mentioned wont be recognized by Clangd anyway.

Do I need to pass some extra arguments or is this simply broken currently? This is the file it generated btw: [https://u.teknik.io/sm3mM.json](https://u.teknik.io/sm3mM.json)

---

<div class="post-metadata">

**Author:** ![officernickwilde](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/officernickwilde/32/547477_2.png) [@officernickwilde](https://forums.unrealengine.com/u/officernickwilde)\
**Post date:** [February 4, 2021, 12:02pm UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/10 "2021-02-04T12:02:27Z")

</div>

Hi everyone, sorry for waking up an old thread. Ive been trying to get LLVM’s language server Clangd working with Unreal Engine, using this cmd:

& ‘D:\Program Files (x86)\Epic Games\UE\_4.26\Engine\Binaries\DotNET\UnrealBuildTool.exe’ Development Win64 BullCowGame “C:\Users\Oliver\Documents\Unreal Projects\BullCowGame-starter-kit\BullCowGame.uproject” -mode=GenerateClangDatabase

I was able to generate a compile\_commands.json in my engine directory. However this file doesnt seem to mention all includes necessary. Like CoreMinimal.h for instance is missing and many includes that in fact are mentioned wont be recognized by Clangd anyway.

Do I need to pass some extra arguments or is this simply broken currently? This is the file it generated btw: [https://u.teknik.io/sm3mM.json](https://u.teknik.io/sm3mM.json)

---

<div class="post-metadata">

**Author:** ![TBBle](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tbble/32/996112_2.png) [@TBBle](https://forums.unrealengine.com/u/TBBle)\
**Post date:** [February 5, 2021, 12:05am UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/11 "2021-02-05T00:05:11Z")

</div>

I don’t understand the problem you’re describing. _compile\_commands.json_ does not normally list individual header files, unless they’re somehow on the command-line (either compiled, or passed to the compiler as a force-include or similar), so I would not expect _CoreMinimal.h_ to be mentioned in the file.

---

<div class="post-metadata">

**Author:** ![officernickwilde](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/officernickwilde/32/547477_2.png) [@officernickwilde](https://forums.unrealengine.com/u/officernickwilde)\
**Post date:** [February 6, 2021, 10:46am UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/12 "2021-02-06T10:46:30Z")

</div>

Yep you are probably right, I havent digged in compile\_commands.json files before.

I got Clangd to read from the file properly a little after posting this by moving the compile\_commands.json from the engine directory to my project directory.

About Kakus comment about adding

```
 CommandBuilder.AppendFormat(" -I\"{0}\"", Module.GeneratedCodeDirectory);

```

to GenerateClangDatabase.cs, does this mean that we can also compile our code with Clang even when working on Windows? Would love some guidance on this as I would prefer using Clang over Microsofts cl.exe.

Are there any build flags for UBT or anything like that which lets you build using Clang? And would it be possible to get it working along with Live coding?

---

<div class="post-metadata">

**Author:** ![Kakus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kakus](https://forums.unrealengine.com/u/Kakus)\
**Post date:** [February 6, 2021, 11:20am UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/13 "2021-02-06T11:20:05Z")

</div>

I’ve managed to compile my project with clang but failed to link it. To do it you have to edit your BuildConfiguration.xml, and add this:

```
  <WindowsPlatform>
    <Compiler>Clang</Compiler>
  </WindowsPlatform>

```

You may want to also modify UEBuildWindows.cs in UBT project, line 721

```
		public static readonly bool bAllowClangLinker = true;
```

---

<div class="post-metadata">

**Author:** ![officernickwilde](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/officernickwilde/32/547477_2.png) [@officernickwilde](https://forums.unrealengine.com/u/officernickwilde)\
**Post date:** [February 6, 2021, 12:50pm UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/14 "2021-02-06T12:50:25Z")

</div>

Hey and thanks for the reply 🙂

You said you didnt get it to link. Was that using the bALlowClangLinker = true; modification?

While I do would prefer Clang Im not sure it would be interesting enough if I would have to deal with longer compile times or having to restart the engine due to it being incompatible with the liver coding feature.

---

<div class="post-metadata">

**Author:** ![Kakus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kakus](https://forums.unrealengine.com/u/Kakus)\
**Post date:** [February 6, 2021, 1:00pm UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/15 "2021-02-06T13:00:14Z")

</div>

I’ve tried with bAllowClangLinker set on and off, but unfortunately without success. Although the issue was with the plugin I use not the project itself. I don’t know whether live coding feature would work with Clang.

---

<div class="post-metadata">

**Author:** ![techsupport\_tyca](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@techsupport\_tyca](https://forums.unrealengine.com/u/techsupport_tyca)\
**Post date:** [April 10, 2023, 7:20am UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/16 "2023-04-10T07:20:31Z")

</div>

With UnrealEngine 5 I was able to do `make ARGS="-mode=GenerateClangDatabase"` to get it to work.

---

<div class="post-metadata">

**Author:** ![meta\_leap](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/meta_leap/32/873171_2.png) [@meta\_leap](https://forums.unrealengine.com/u/meta_leap)\
**Post date:** [December 19, 2023, 7:51pm UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/17 "2023-12-19T19:51:59Z")

</div>

Lucky you, for me running that in the very workspace dir with the `Makefile` throws with:

```auto
make: *** No rule to make target 'CrashReportClient-Linux-Shipping', needed by 'RequiredTools'. Stop.

```

I open the file and behold, `CrashReportClient-Linux-Shipping` is _mentioned_ in `RequiredTools:` but _defined_ — nowhere.

What now brown cow…

---

<div class="post-metadata">

**Author:** ![dzemzmcdonalda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dzemzmcdonalda/32/1214680_2.png) [@dzemzmcdonalda](https://forums.unrealengine.com/u/dzemzmcdonalda)\
**Post date:** [August 12, 2024, 1:11pm UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/18 "2024-08-12T13:11:37Z")

</div>

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):

```auto
"/home/korn/UnrealEngine/Engine/Build/BatchFiles/Linux/Build.sh" \
	-mode=GenerateClangDatabase \
	-NoExecCodeGenActions \
	-project=/home/korn/Tlob/Tlob.uproject \
	-game \
	-engine \
	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:

```auto
ln \
	-sfv \
	/home/korn/UnrealEngine/compile_commands.json \
	/home/korn/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](https://github.com/williamboman/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.~~ (Fixed, see my next comment)
- 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:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/1/b/e1bc094460e0cfc759a374042c657a50b645f0dc.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/0/e/b0e757b358c6ed84821a53a31c4c80b6637f8862.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/2/a/02a37841cebddac00927b01d97d09a394a7e39e4.png)

---

<div class="post-metadata">

**Author:** ![GoyoElGringo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GoyoElGringo](https://forums.unrealengine.com/u/GoyoElGringo)\
**Post date:** [September 19, 2024, 1:13pm UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/19 "2024-09-19T13:13:55Z")

</div>

Works brilliantly, thank you!

---

<div class="post-metadata">

**Author:** ![dzemzmcdonalda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dzemzmcdonalda/32/1214680_2.png) [@dzemzmcdonalda](https://forums.unrealengine.com/u/dzemzmcdonalda)\
**Post date:** [September 20, 2024, 7:31pm UTC](https://forums.unrealengine.com/t/get-compile-commands-json/433389/20 "2024-09-20T19:31:41Z")

</div>

Small update on this:

- I just found that there is `-NoExecCodeGenActions` flag for GenerateClangDatabase which fixes the issues with super long execution times of this mode. For context, see [UBT GenerateClangDatabase is NOT incremental and recreates whole compile\_commands.json each time](https://forums.unrealengine.com/t/ubt-generateclangdatabase-is-not-incremental-and-recreates-whole-compile-commands-json-each-time/2005308)
- I also found there is a wrapper for GenerateClangDatabase inside of `ushell` and its code is located here: [UnrealEngine/Engine/Extras/ushell/channels/unreal/core/cmds/clangdb.py](https://github.com/EpicGames/UnrealEngine/blob/40eea367040d50aadd9f030ed5909fc890c159c2/Engine/Extras/ushell/channels/unreal/core/cmds/clangdb.py) - this command is invoked by `.build misc clangdb` but I haven’t tested it yet.
- adding `-allmodules` flag generates a bit bigger `compile_commands.json`. Not sure if this fixes/changes anything. I haven’t noticed any difference on my side yet beside way longer execution times (so I don’t recommend using it).
