What causes linker warning "MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG"?

Visual StudioVisual Studio-2013Linker

Visual Studio Problem Overview


Some projects in my solution produce this linker warning:

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

I'm using Visual Studio 2013 Update 3. I haven't yet been able to identify anything particular to those projects that could cause this.

What is it about those projects that produces this?


I've looked at this: http://msdn.microsoft.com/en-us/library/k669k83h.aspx but I'm not aware we are using any CLR, managed code, /LN or /NOASSEMBLY.

Visual Studio Solutions


Solution 1 - Visual Studio

I had the same problem, so I did some research.

According to https://msdn.microsoft.com/en-us/library/0zza0de8.aspx :

> If you compile your program with /GL and /c, you should use the /LTCG > linker option to create the output file.

So the message can be a bit misleading - the problem is not the MSIL .netmodule, but modules compiled with /GL

When using /GL, you tell the compiler to delay the generation of some code namely around function bounderies, in order to optimise them. LTCG instruct the linker to generate (and optimise) the missing code. Otherwise, the program will not run as expected.

Basically, the two switches should be used together (when used). They apply to different parts of the build: one for compilation and the other one for link.

For completeness:

  • /GLis controlled from Configuration Properties > C/C++ > Optimization > Whole Program Optimization

  • /LTCG is controlled from Configuration Properties > Linker > Optimization > Whole Program Optimization

On later versions,

  • /LTCG is controlled from Configuration Properties > Linker > Optimization > Link Time Code Generation / Use Link Time Code Generation (/LTCG)

Solution 2 - Visual Studio

I have encountered the same error and spent quite a lot of time trying to fix it. Finally, I figured out that it appeared due to the use of "Whole Program Optimization" option in one of my dependency libraries.

By default, this option is set to "Yes" in newly created projects. When I changed it to "No" and recompiled all dependencies, the warning disappeared. I have purely native C++ solution without any managed code.

To fix, open project settings of all dependency projects and check setting:

Configuration Properties > C/C++ > Optimization > Whole Program Optimization

Make sure it is set to "No" everywhere.

Solution 3 - Visual Studio

I find the same error goes away by telling the linker about /GL setting you have used:

Set ... Configuration Properties/Linker/Optimization/Link Time Code Generation To ... One of the non-Default settings

Maybe https://msdn.microsoft.com/en-us/library/xbf3tbeh.aspx is of some use?

Neil

Solution 4 - Visual Studio

This message shows a lot, which is really raising suspicion. I use a property sheet which tells both /GL and /LTCG. The project isn't using any external libraries. And I get this message, which doesn't make any sense. It disappears, if I go to the project properties and specify "Use Link Time Code Generation" again from there. It doesn't change the command line or anything, but just makes VC happy...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionScott LanghamView Question on Stackoverflow
Solution 1 - Visual StudioIonel POPView Answer on Stackoverflow
Solution 2 - Visual StudioBoris ZinchenkoView Answer on Stackoverflow
Solution 3 - Visual StudioNeil GatenbyView Answer on Stackoverflow
Solution 4 - Visual Studiojj99View Answer on Stackoverflow