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

Solution 1:

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:

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.