/Gw (Optimize Global Data)

Package global data in COMDAT sections for optimization.

Syntax

/Gw[-]

Remarks

The /Gw option causes the compiler to package global data in individual COMDAT sections. By default, /Gw is off and must be explicitly enabled. To explicitly disable it, use /Gw-. When both /Gw and /GL are enabled, the linker uses whole-program optimization to compare COMDAT sections across multiple object files in order to exclude unreferenced global data or to merge identical read-only global data. This can significantly reduce the size of the resulting binary executable.

When you compile and link separately, you can use the /OPT:REF linker option to exclude from the executable the unreferenced global data in object files compiled with the /Gw option.

You can also use the /OPT:ICF and /LTCG linker options together to merge in the executable any identical read-only global data across multiple object files compiled with the /Gw option.

For more information, see Introducing /Gw Compiler Switch on the C++ Team Blog.

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.

  2. Select the C/C++ folder.

  3. Select the Command Line property page.

  4. Modify the Additional Options property to include /Gw and then choose OK.

To set this compiler option programmatically

See also

MSVC Compiler Options
MSVC Compiler Command-Line Syntax