Several compilation options I use with C++ projects in Visual Studio

— richardwb on Thursday, March 12, 2009 @ 16:39

These are compilation options that I typically enable for any C++ projects in Visual Studio. They should go in the project's property settings, under Configuration Properties->C/C++->Command Line, in the Additional options textbox. They are listed here exactly as they should be entered in that box (equal signs and all).

  • /MP : This enables multi-process compilation, which can provide a significant speed boost on the multi-core processor you likely have in your development (or build) machine. As the MSDN documentation states, it is not compatible with the Enable Minimal Rebuild option, which, depending on the situation, may negate any performance advantage this switch has. Disabling minimal rebuild is not as bad as it sounds1 and in my projects I've found that using /MP confers a significant improvement in compilation time. You definitely want to enable it for Release builds, at least. Reference.
  • /D_CRT_SECURE_NO_WARNINGS : This switch disables the warnings that Visual Studio spits out if you use any of the C RunTime functions that Microsoft has provided secure replacements for (such as strncpy). This isn't necessarily a bad idea, but their safe functions are not part of the standard and are thus non-portable. Reference.
  • /D_SCL_SECURE_NO_WARNINGS : Just like the switch above, only for the Standard C++ Library (anything in the std namespace). Reference.
  • /D_SECURE_SCL=0 : Disables checked iterators. Disabling this feature can improve performance when using iterators, at the expense of less protection against unsafe iterator use. Generally there isn't too much of a performance difference (a Visual C++ lead states that they measured about a 6% difference in this feedback / bug page) so it may be worth leaving it on most of the time. Reference.

Note that /D_CRT_SECURE_NO_WARNINGS and /D_SCL_SECURE_NO_WARNINGS are /D_CRT_SECURE_NO_DEPRECATE and /D_SCL_SECURE_NO_DEPRECATE, respectively, in versions prior to Visual Studio 2008.

  1. Disabling Minimal Rebuild does not mean that the whole project gets rebuilt every time, just that Visual Studio uses a "was this .cpp/.h modified?" approach instead of trying to determine if the exact changes you made warrant a recompile. 

comments powered by Disqus