/OPT (Optimizations)

Controls the optimizations that LINK performs during a build.

/OPT:{ICF[=iterations] | NOICF}


    /OPT:REF eliminates functions and/or data that are never referenced while /OPT:NOREF keeps functions and/or data that are never referenced.

    LINK removes unreferenced packaged functions by default. An object contains packaged functions (COMDATs) if it has been compiled with the /Gy option. This optimization is called transitive COMDAT elimination. To override this default and keep unreferenced COMDATs in the program, specify /OPT:NOREF. You can use the /INCLUDE option to override the removal of a specific symbol.

    If /DEBUG is specified, the default for /OPT is NOREF (otherwise, it is REF), and all functions are preserved in the image. To override this default and optimize a debugging build, specify /OPT:REF. The /OPT:REF option disables incremental linking.

    You have to explicitly mark data as a COMDAT; use __declspec(selectany).

    If /OPT:REF is specified, /OPT:ICF is on by default. If you want /OPT:REF but not /OPT:ICF, you must specify the following:

    link /opt:ref /opt:noicf

    Specifying /OPT:ICF does not activate the /OPT:REF option.

  • ICF[= iterations**] | NOICF**
    Use /OPT:ICF[=iterations] to perform identical COMDAT folding. Redundant COMDATs can be removed from the linker output. iterations specifies the number of times to traverse the symbols for duplicates. The default number of iterations is two. Additional iterations may locate more duplicates uncovered through folding in the previous iteration.

    Note that there is a difference in linker behavior when ICF is in effect by default with /OPT:REF explicitly specified and when you explicitly specify /OPT:REF,ICF. The default ICF with /OPT:REF does not fold read-only data. This includes any .rdata, .pdata, and .xdata. However, the default ICF with /OPT:REF results in fewer functions folded when producing images for Itanium and x64 because functions in these modules have more read only data dependency, such as .pdata and .xdata. To get full ICF, explicitly specify /OPT:ICF.

    Functions are placed in COMDATs with the /Gy compiler option and const data is placed in COMDATs. See selectany for an example of how to specify data for folding.

    ICF is on by default if REF is on and needs to be explicitly turned on in a debug build. It is possible to specify NOICF if REF is specified.


    /OPT:ICF can result in the same address being assigned to different functions or read only data members (const variables compiled with /Gy). So, /OPT:ICF can break a program that depends on the address of functions or read-only data members being different. See /Gy (Enable Function-Level Linking) for more information.


Optimizations generally decrease the image size and increase the program speed at a cost of increased link time.

You can use the /VERBOSE option to see the functions removed by /OPT:REF and the functions that are folded by /OPT:ICF.

To set this linker option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.

  2. Click the Linker folder.

  3. Click the Optimization property page.

  4. Modify one of the following properties:

    • Enable COMDAT Folding

    • Optimize for Windows 98

    • References

To set this linker option programmatically

See Also


Setting Linker Options

Linker Options