Using different toolsets for vc build

Hi,

 

I am Olga Arkhipova and I am a VC IDE developer. I joined VC team about two years ago and inherited vc project and build system.  I’ve been using VC since VC2, so for me it is quite interesting to see and work on the code I’ve been using (or sometimes not using, because it did not do what I needed) for so long J

 

As VS9 has now shipped together with new compilers and libraries, several people inside Microsoft asked me how vc build finds its build tools (cl, link, different libraries and includes) and if it is possible to use a different VC toolset rather than those installed with VS (for instance, use vs9 from vs8 and vice versa, or a particular SDK toolset), so I decided it might be useful  to blog about this question for other people. Yes, it is possible and the information on how to do this does exist on MSDN, but it appears to be hard to find and it is split into pieces.

 

To define a toolset for the command line build you need to:

 

·         Set INCLUDE, LIB, LIBPATH and PATH environment variables to point to the corresponding directories of the toolset you want to use (LIBPATH is for managed References dirs). Something like

set  MyToolSetRoot =c: MyToolSet

set INCLUDE=”%MyToolSetRoot%include;%MyToolSetRoot%atlmfcinclude;%MyToolSetRoot%SDKinclude;

 

·         Run ‘devenv /useenv’ or ‘vcbuild /useenv’ to force using defined locations instead of standard VS ones.

 

Note that those directories you set will be used for all platforms, so if you need to build for more than one platform, you’ll have to define INCLUDE, LIB, LIBPATH and PATH for each of them and build them separately, say, by running ‘vcbuild /platform:<str> …’

 

To see what VS9 (and I believe VS8) sets for different platforms, you can take a look at

c:Program FilesMicrosoft Visual Studio 9.0VCbinvsvars32.bat

 

And if you installed 64-bit platform support:

c:Program FilesMicrosoft Visual Studio 9.0VCbinx86_ia64vcvarsx86_ia64.bat   (cross platform tools)

c:Program FilesMicrosoft Visual Studio 9.0VCbinx86_amd64vcvarsx86_amd64.bat (cross platform tools)

c:Program FilesMicrosoft Visual Studio 9.0VCbinia64vcvarsia64.bat ( native 64-bit tools, installs only on 64bit OS)

c:Program FilesMicrosoft Visual Studio 9.0VCbinamd64vcvarsamd64.bat ( native 64-bit tools, installs only on 64bit OS)

 

 

You can also change the vc build toolset for the VS IDE.

 

Start VS,  go to Tools – Options – Projects and Solutions – VC++ Directories  and modify directories for ‘Executable files’, ‘Include files’, ‘Library files’ and ‘Reference files’ to point to your toolset directories. You can use environment variables as macros there. For instance, if you have ‘MyToolSetRoot’ environment variable defined on your machine, for ‘Include files’ you can set:

 

$( MyToolSetRoot)include

$( MyToolSetRoot)atlmfcinclude

$( MyToolSetRoot)SDKinclude

 

Do this for all platforms you build for. Close the dialog. These will modify the options per user/per machine. If you want to switch between different VC directories on your machine or share them to another machine, in VS9 and VS8(sp1) you can use Tools – Import/Export settings (VS8 does not support this). The VC++ directories are not imported/exported by default (as they might contain only this machine specific directories), so you need to check  All Settings – Options – Projects – VC++ Directories explicitly.

 

Thanks,

Olga