# How to set linker flags (/LTCG)?

**URL:** <https://forums.unrealengine.com/t/how-to-set-linker-flags-ltcg/377340>\
**Category:** C++\
**Tags:** linker, unreal-engine, question, CPP\
**Created:** [November 24, 2016, 9:11pm UTC](https://forums.unrealengine.com/t/how-to-set-linker-flags-ltcg/377340 "2016-11-24T21:11:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_f3fb80e6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f3fb80e6](https://forums.unrealengine.com/u/anonymous_user_f3fb80e6)\
**Post date:** [November 24, 2016, 9:11pm UTC](https://forums.unrealengine.com/t/how-to-set-linker-flags-ltcg/377340/1 "2016-11-24T21:11:45Z")

</div>

I am using a static library (.lib) in my UE4 project. That basically works fine, however, I get the following warning during compilation:

_“MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance”_

Now according to [MSDN](https://msdn.microsoft.com/en-us/library/0zza0de8.aspx) this problem is based on the fact that the library is compiled with the /GL flag turned on (= Whole Program Optimization), but for the UE4 project the linker does not use the /LTCG flag (whereas both shoud be used or none).

So my question: How can I tell the linker in my UE4 project to use this /LTCG flag?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e1600e71](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e1600e71](https://forums.unrealengine.com/u/anonymous_user_e1600e71)\
**Post date:** [November 25, 2016, 8:30am UTC](https://forums.unrealengine.com/t/how-to-set-linker-flags-ltcg/377340/2 "2016-11-25T08:30:43Z")

</div>

Hi !

If you want to change the linker flag, you have to rebuild UnrealBuildTool from source. You can download it from the git repository.

Open the _CVToolChain.cs_ file and there you will find all command line parameters used with _cl.exe_. Just add your linker flag at the proper spot (according to your build configurations needs).

Then just rebuild the UE4 target from your project’s Visual Studio Solution and the changes will be applied.

To make sure you linker flag has been taken in account, I suggest you add “_–verbose_” to your NMake parameters (right click on your project target, properties, NMake).

Good luck ! Best regards.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f3fb80e6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f3fb80e6](https://forums.unrealengine.com/u/anonymous_user_f3fb80e6)\
**Post date:** [November 25, 2016, 11:56am UTC](https://forums.unrealengine.com/t/how-to-set-linker-flags-ltcg/377340/3 "2016-11-25T11:56:28Z")

</div>

So as I found out all you need to do is to enable the following flag in the .Build.cs file (within the constructor):

```
BuildConfiguration.bAllowLTCG = true;

```

This enables the /LTCG flag for Shipping builds.  
Cheers!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f3fb80e6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f3fb80e6](https://forums.unrealengine.com/u/anonymous_user_f3fb80e6)\
**Post date:** [November 25, 2016, 11:57am UTC](https://forums.unrealengine.com/t/how-to-set-linker-flags-ltcg/377340/4 "2016-11-25T11:57:32Z")

</div>

Thanks. I have however found another solution, which works without recompiling the UBT. See my (accepted) answer to this question.
