Getting Boost to Compile Correctly with Visual Studio 10 & CUDA on a 64-bit Machine

Sexy title, I know!

Anyways, I’m developing using Visual Studio 10 (not my choice).  I have a project which involves the use of CUDA and Boost. The newest version of CUDA (at the time of this writing) won’t work out of the box with the  vs100 compiler that comes with Visual Studio 10.  CUDA can use nothing newer than the vs90 compiler.  So, I  install visual studio 9 and 10 and select v90 as my compiler for my Visual Studio 10 project.

Yesterday, I needed the Boost C++ libraries and began to install them.

The Boost installation is pretty good.  Its fairly automated which is nice.  You essentially call bootstrap and then bjam; they take care of all the configuring and building of the .libs.  However,  Boost’s scripts see that I have Visual Studio 10 installed and compile everything with the vs100 compiler.  This breaks my project in  Visual   Studio (I get all linking errors related to Boost) as I’m in  Visual Studio 10, but using the v90 compiler because of CUDA.

So, I figured out how to override Boost’s configuration to compile with the vn90 compiler instead of the vc100 compiler.  Here is how I fixed the problem.

 cd to BOOST_ROOT
 boostrap
 "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat"    // This invokes the vc90 environment variable set.
 bjam --toolset=msvc-9.0 --build-type=complete architecture=x86 address-model=64  // Makes Boost!

If you don’t run the 3rd line (vsvars64.bat), you will see tons of “cl” errors when running  bjam.  Essentially, Boost tries to call the vc90 compiler (cl.exe), but because the environment is hosed, it cant find it and bombs.