# ProjectDefinitions / Precompiler Definitions in Target.cs and Building via Command Line

**URL:** <https://forums.unrealengine.com/t/projectdefinitions-precompiler-definitions-in-target-cs-and-building-via-command-line/2140691>\
**Category:** C++\
**Tags:** unreal-engine, question\
**Created:** [November 21, 2024, 1:35pm UTC](https://forums.unrealengine.com/t/projectdefinitions-precompiler-definitions-in-target-cs-and-building-via-command-line/2140691 "2024-11-21T13:35:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NEVQ151](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NEVQ151](https://forums.unrealengine.com/u/NEVQ151)\
**Post date:** [November 21, 2024, 1:35pm UTC](https://forums.unrealengine.com/t/projectdefinitions-precompiler-definitions-in-target-cs-and-building-via-command-line/2140691/1 "2024-11-21T13:35:06Z")

</div>

Hi,

I am compiling our project via RunUAT:

```auto
call %UE_5.3%/RunUAT.bat BuildCookRun -noP4 -utf8output -cook -project="%cd%/ProjectName.uproject" -platform=Win64 -stage -archive -package -build -pak -iostore -compressed -prereqs -archivedirectory="%cd%/PackagedBuilds/EGSWindows" -clientconfig=Shipping -nodebuginfo -target=ProjectNameEGS

```

I am specifying a custom target that points to a custom Target.cs file for Epic Game Store that looks like this:

```auto
public class MyGameEGSTarget : TargetRules
{
	public MyGameEGSTarget( TargetInfo Target) : base(Target)
	{
        Type = TargetType.Game;
        DefaultBuildSettings = BuildSettingsVersion.V2;
        ExtraModuleNames.AddRange(new string[] { "MyGame" });

        IncludeOrderVersion = EngineIncludeOrderVersion.Latest;

        CustomConfig = "EGS";

        ProjectDefinitions.Add("PLATFORM_EGS=1");
    }
}

```

I am using the precompiler check like this in C++:

```auto

#if PLATFORM_EGS
	LoginEGS(Identity, UserIndex);
#elif PLATFORM_STEAM
	LoginSteam(Identity, UserIndex);
#endif

```

Still, when compiling the target, RunUAT shows the following error:

```auto
[171/932] Compile [x64] CreateSessionRequest.cpp
...\Private\Services\CreateSessionRequest.cpp(27): error C4668: 'PLATFORM_EGS' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
...\Private\Services\CreateSessionRequest.cpp(29): error C4668: 'PLATFORM_STEAM' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'

```

Why is this happening?

I noticed that the output log shows that among other targets, the following is being built: `-Target="MyGameEditor Win64 Development `

Does this mean that effectively the precompiler settings from the MyGameEditor.target.cs are being used? Adding the PLATFORM\_EOS=1 flag in MyGameEditor.target.cs fixes the error, but that is not what I want, since I need different targets defined per the CLI in order to build for all platforms.

Or am I building two targets (Editor and EGS)? If yes, is there a way to remove the Editor target from the build?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![NEVQ151](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NEVQ151](https://forums.unrealengine.com/u/NEVQ151)\
**Post date:** [November 21, 2024, 6:57pm UTC](https://forums.unrealengine.com/t/projectdefinitions-precompiler-definitions-in-target-cs-and-building-via-command-line/2140691/2 "2024-11-21T18:57:35Z")

</div>

Okay I have been able to fix this and it took me a few hours, so I am leaving my findings here in case anyone comes across a similar issue.

First of all, there is the RunUAT BuildCookRun parameter -NoCompileEditor, which will skip the -Target=“MyGameEditor Win64 Development” that is passed to the UnrealBuildTool.dll automatically. However doing that resulted in an error that the plugin VisualStudioTools could no longer be found or similar. I am no longer able to reproduce this error and currently I can use the -NoCompileEditor token without issues. It could be that it is required to build the editor and right now it only works because I did not clean before building.

However the -NoCompileEditor flag is not needed. It seems that without -NoCompileEditor the .cpp files are compiled twice, once for the Editor target and once for MyGameEGS target. The problem was in my code, where I used this:

```auto
#if PLATFORM_EGS
	LoginEGS(Identity, UserIndex);
#elif PLATFORM_STEAM
	LoginSteam(Identity, UserIndex);
#endif

```

This would always result in the compile error I posted earlier, because my editor target does not define any of these. The correct way would be to check if any of them is actually defined like so:

```auto
#ifdef PLATFORM_EGS
	LoginEGS(Identity, UserIndex);
#elif defined(PLATFORM_STEAM)
	LoginSteam(Identity, UserIndex);
#endif

```

This way, the compiler will not complain, even if none of them are defined. Furthermore the MyGameEGS target compiles correctly with the PLATFORM\_EGS flag being defined from the MyGameEGS.Target.cs file, even though the Editor target is compiled alongside without the PLATFORM\_EGS Flag.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [December 21, 2024, 6:58pm UTC](https://forums.unrealengine.com/t/projectdefinitions-precompiler-definitions-in-target-cs-and-building-via-command-line/2140691/3 "2024-12-21T18:58:00Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
