/Gw (Optimize Global Data)
The latest version of this topic can be found at -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 Visual C++ Team Blog.
To set this compiler option in the Visual Studio development environment
Open the project's Property Pages dialog box. For details, see Working with Project Properties.
Select the C/C++ folder.
Select the Command Line property page.
Modify the Additional Options property to include /Gw and then choose OK.
To set this compiler option programmatically
- See AdditionalOptions.