Optimized Linking

Optimized linking (compiling with /Gl or linking with /OPTFUNC) generally takes longer than regular linking. However, if the optimization is effective enough, it can actually speed up the linking process, because there is less information to write to file. The linker produces slightly faster and more compact code and files by grouping neighboring sections that have similar attributes.

As a general rule, it is best to link without the /OPTFUNC option until your code is tested and stable.

Removing Unreachable Functions
Just as the compiler can optimize your source code by removing or replacing instructions, the linker can optimize your object code, including code in libraries you are linking in, by removing unreferenced functions. When the function is removed, any code that was required only by that function is also removed, including any other functions that were referenced only by that function. This reduces the size of your output file.

Compile with the option /Gl, and then link with the option /OPTFUNC, to remove functions that are:

If you are compiling and linking in one step, you do not need to specify /OPTFUNC. The compiler passes /OPTFUNC to the linker automatically when you specify /Gl.

Reducing the size of the executable file and improving performance

Note: Your code must be compiled with Gl+ to remove unreferenced functions.



Linking


Summary of Linker Options