Following my last blog about
Building Boost with MinGW, here I'm going to show you step-by-step how to build Boost with Visual C++ 2010 Express. The latest Boost as of this writing is 1.48.0, so I'm going to use that version.
- Download Visual C++ 2010 Express from Microsoft website and install it.
- Download Windows SDK. This is optional, but it can be pretty useful if you plan to call any Windows API.
- Download Boost from Boost website.
- Extract Boost to any location of you preference.
- Modify the C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat as shown below. You need to edit this file as an Administrator. Visual C++ 2010 Express seems to have a bug for not setting all these variables automatically. You need to uncomment the first 3 lines. Setting WindowsSdkDir is optional if you skipped step 2.
:: @call :GetVSCommonToolsDir
:: @if "%VS100COMNTOOLS%"=="" goto error_no_VS100COMNTOOLSDIR
:: @call "%VS100COMNTOOLS%VCVarsQueryRegistry.bat" 32bit No64bit
@SET WindowsSdkDir=C:\Program Files\Microsoft SDKs\Windows\v7.1\
@SET VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio 10.0\
@SET VCINSTALLDIR=C:\Program Files\Microsoft Visual Studio 10.0\VC\
@SET VS100COMNTOOLS=%VSINSTALLDIR%\Common7\IDE\
@SET PATH=%PATH%;%VCINSTALLDIR%\bin;%VS100COMNTOOLS%
@SET FrameworkDir32=C:\Windows\Microsoft.NET\Framework
@SET FrameworkVersion32=v4.0.30319
@SET Framework35Version=v3.5
- Open Visual Studio Command Prompt (2010) and go to your boost installation directory.
- Build Boost build tool (b2).
[boost_dir]\bootstrap.bat
- Build Boost (you can start making your coffee or do whatever you like since this process is gonna take a while). All the libraries will be created in the stage\lib folder.
[boost_dir]\b2.exe toolset=msvc --build-type complete stage
- Open your Visual C++ 2010 Express and create a new Win32 Console project.
- Right click on the project --> Properties--> Configuration Properties --> C/C++ --> General and add [boost_dir] in the Additional Include Directories.
- In the same Properties window Configuration Properties --> Linker --> General, add [boost_dir]\stage\lib in the Additional Library Directories.
- Let's now test our Boost libraries.
#include "stdafx.h"
#include <string>
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/regex.hpp>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
boost::shared_ptr<string> ptr(new string("Hello World, Boost"));
boost::smatch matches;
boost::regex pattern("Hello World,\\s*(.*)");
boost::regex_match(*ptr, matches, pattern);
cout << matches[1] << endl;
system("pause");
return 0;
}
\b2.exe toolset=msvc ==build-type complete stage
ReplyDeletefailed for unknown feature "<>"
command should be:
.\b2.exe toolset=msvc --build-type=complete stage
It was a typo. Fixed it. Thanks!
ReplyDeleteThank you very much.its really work.finally i setup boost with vc++ express after 3 days.thank you again
ReplyDelete