Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 340
Scott Langham Avatar asked Oct 09 '14 13:10

Scott Langham


People also ask

What is an MSIL module?

A managed program that does not have an assembly metadata in the manifest is called a module. If you compile with /c (Compile Without Linking) and /LN, specify /NOASSEMBLY (Create a MSIL Module) in the linker phase to create the output file.

What is Link Time Code Generation?

Link-time code generation (LTCG) enables cross source-file optimization by delaying code generation until the link stage. This can significantly reduce code size. To enable LTCG, compile your source with -c --ltcg to create objects in an intermediate format.


2 Answers

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)
like image 51
Ionel POP Avatar answered Oct 12 '22 16:10

Ionel POP


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.

like image 44
Boris Zinchenko Avatar answered Oct 12 '22 16:10

Boris Zinchenko