14

I'm using Visual Studio 2008 on my main build system. I've been playing with Visual Studio 2010 on another one. It appears that the tool still only wants to use one core when compiling unless you specify the /MP switch in the compiler switches (see How do I turn on multi-CPU/Core C++ compiles in the Visual Studio IDE (2008)?). I have to do this for every project. Is there a way to make VS always do this?

1
  • 1
    I've added the [visual-c++] tag since I think the /MP flag is specific to the VC++ compiler. Commented Apr 23, 2010 at 0:44

2 Answers 2

18

Create environment variable "CL" and set it to "/MP". Microsofts compiler cl.exe always prepend command line flags with this variable.

Some compiler features and options like #import aren't compatible with /MP flag. You will need to add /MP1 to projects used #import in a code. This will disable /MP for those projects.

6
  • 1
    The issue with #import is well explained in C2813, which is the error you'll get when using the /MP switch in VS2008 and above. (Note: VS2005 also has the undocumented /MP switch, but it hasn't got this error.)
    – Martin Ba
    Commented Feb 12, 2014 at 13:41
  • 1
    The rest of the incompatible features are described here
    – gallo
    Commented Oct 28, 2016 at 21:53
  • @ZAB I'm pretty sure (but would like your opinion/experience) that the value needs to be " /MP". Notice the space - without it, the environment variable didn't have the desired effect (still only one core was used).
    – codeling
    Commented Aug 8, 2017 at 9:53
  • @codeling have you reopened studio after environment variable change?
    – ZAB
    Commented Aug 10, 2017 at 13:18
  • 1
    Minor qualification: it's not necessary to use /MP1 for an entire project if just a couple of files use #import. In project files (certainly for Visual Studio 2017) one can turn it off for selected source files using <ClCompile Include="foo.cpp"> <MultiProcessorCompilation>false</MultiProcessorCompilation> </ClCompile>
    – egyik
    Commented Jan 25, 2019 at 9:20
6

Your can create a property sheet that all of your projects include, and set the /MP flag in that property sheet.

In Visual Studio 2010, you could put it in the Microsoft.Cpp.Win32.user property sheet, which is included in new projects by default (it has the old Visual C++ directories and other default settings defined in it). I don't know that modifying the default property sheet is really a good idea, but it's certainly an option.

4
  • From this msdn.microsoft.com/en-us/library/3z7t21ew%28v=VS.90%29.aspx it looks like I still have to go into each project and tell it to inherit the property sheet.
    – dwj
    Commented Apr 23, 2010 at 0:42
  • @dwj: You would, yes. Note also what I just added about Visual C++ 2010. Commented Apr 23, 2010 at 0:43
  • Modifying included templates always makes me nervous; I forget to do it if I reinstall! Thanks for the pointers; I was really hoping MS either made /MP the default or allowed it to always be turned on for a given developer/environment.
    – dwj
    Commented Apr 23, 2010 at 0:52
  • @dwj: Sadly, no, and it doesn't sound like that will change too soon: connect.microsoft.com/VisualStudio/feedback/details/467801/… Commented Apr 23, 2010 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.