IT lexicon › Programming › LTCG (link-time code generation)

LTCG (link-time code generation)

Programming På svenska → Updated: 2026-11-07

Microsoft's flavour of link-time optimization, in which the compiler leaves intermediate code in the object files and the linker finishes the compilation.

In MSVC it takes two switches: /GL when compiling each file and /LTCG when linking. Visual Studio calls the same thing Whole Program Optimization, and it was already in Visual C++ .NET 2002, years before GCC had an equivalent. Microsoft's profile-guided optimization was built on top of it: an instrumented link, a training run, and a second link using the profile.

The catch is that objects compiled with /GL contain no machine code, only an internal format that the exact same compiler version understands. A static library built that way cannot be shipped to customers on a different Visual Studio, and anyone who tries gets a link error that points somewhere unhelpful. Visual Studio 2015 added /LTCG:INCREMENTAL, which regenerates code only for the functions a change actually affected.

← Back to the lexicon