# Emacs, Clangd and Unreal Engine

**URL:** <https://forums.unrealengine.com/t/emacs-clangd-and-unreal-engine/246457>\
**Category:** Community & Industry Discussion\
**Tags:** unreal-engine\
**Created:** [August 20, 2021, 5:40am UTC](https://forums.unrealengine.com/t/emacs-clangd-and-unreal-engine/246457 "2021-08-20T05:40:04Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![drcxd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@drcxd](https://forums.unrealengine.com/u/drcxd)\
**Post date:** [August 20, 2021, 12:07pm UTC](https://forums.unrealengine.com/t/emacs-clangd-and-unreal-engine/246457/2 "2021-08-20T12:07:45Z")

</div>

I dig into the code and found more useful information.

# Include Directories

First the command I used to generate the compile database is

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

```

Then I checked some of the error messages clangd prompted. First, it said it can not find the include file `sal.h`. After some simple research I found that this file is a Windows exclusive file and does not exist in WSL. This is reasonable since the command specified that the target platform is `Win64`. I came up two methods to solve this problem.

## Switch to Another Platform

First, I could change the UBT command to specify other platform such as `Clang` or `Linux`. Here is the output:

```auto
PS D:\workplace\UnrealEngine\Engine\Binaries\DotNET> .\UnrealBuildTool.exe -mode=GenerateClangDatabase -project="D:\workplace\LearnUnreal\LearnUnreal.uproject" -game -engine LearnUnreal Development Clang
ERROR: No platforms specified for target
PS D:\workplace\UnrealEngine\Engine\Binaries\DotNET> .\UnrealBuildTool.exe -mode=GenerateClangDatabase -project="D:\workplace\LearnUnreal\LearnUnreal.uproject" -game -engine LearnUnreal Development Linux
ERROR: Platform Linux is not a valid platform to build. Check that the SDK is installed properly.

```

I am not familiar with UBT and am still reading these documents, so for now I do not know how to proceed in this way.

## Add Include Directories

The other method is to either configure UBT to include the Windows specific include directories in the output compile database or we add them to the compile database manually. Again, I do not know how to configure UBT to include those additional include directories. Although I could add them manually myself, it looks much like a hack not a formal solution.

# Macro Substitution

Then I found that Cland has difficulties in expanding Unreal Engine macros. For example, `UCLASS` is expanded to

```auto
BODY_MACRO_COMBINE(CURRENT_FILE_ID,_, __LINE__ ,_PROLOG)

```

The macro is defined as

```auto
#if UE_BUILD_DOCS || defined( __INTELLISENSE__ )
#define UCLASS(...)
#else
#define UCLASS(...) BODY_MACRO_COMBINE(CURRENT_FILE_ID,_, __LINE__ ,_PROLOG)
#endif

```

Microsoft Visual Studio could expand this macro correctly because the flag ` __INTELLISENSE__ ` is defined. However, this is not true for the compile database generated for Clang. Again, we could manually add the definition to the command database, but I prefer more general solution.

Another macro is `GENERATED_BODY`, it is defined as:

```auto
#define GENERATED_BODY(...) BODY_MACRO_COMBINE(CURRENT_FILE_ID,_, __LINE__ ,_GENERATED_BODY);

```

Clangd complains this with `C++ requires a type specifier for all declarations`. I do not know how MSVS deals with this, but it is obvious these macros are preventing Clangd from compiling the code. Thus it can not correctly find definitions for all the symbols.

I hope there will be some one who can help with this.

---

_[View the full topic](https://forums.unrealengine.com/t/emacs-clangd-and-unreal-engine/246457)._
