What is the Microsoft Visual Studio equivalent to GCC ld option --whole-archive

To my knowledge, there is no single option which reliably guarantees that. There are combinations of optimizing options which (silently) deactivate this, so no way... /INCLUDE works, but for that you need to extract and hardcode the mangled name of the symbol. You have two choices: (1) ensure, that all registrars are contained (included) in the translation unit containing main and enforce their usage. (2) Give up this 'idiom' and use explicit registration.

Caution: this answer is now almost 7 years old and the statements regarding the availability of options in the MSVC++ toolchain are outdated. Nevertheless I still recommend not to rely on registrar pattern and look at the alternatives. Please feel free to down vote because of this recommendation but I guess it's a bit unfair to down vote because the option was added to Microsoft linker in the meantime.


The version of Visual C++ in Visual Studio 2015 Update 2 includes a new flag to link.exe called /WHOLEARCHIVE, which has equivalent functionality to the --whole-archive option to ld. According to the flag documentation:

The /WHOLEARCHIVE option forces the linker to include every object file from either a specified static library, or if no library is specified, from all static libraries specified to the LINK command.