How to set linker flags (/LTCG)?

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 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?

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.

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!

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