C + + has a powerful boost, and there are a lot of features that are not supported by the C + + standard library. Look at the boost of those powerful functional templates how can not be tempted! Let's take a look at how to use the Boost library under VS2010.
System: Windows7
Development environment: Visual Studio 10
Boost version: Boost_1_55_0
(1) Boost Download
Download the latest boost installation package from the Boost official download website, and unzip it in [D:\ProgramFiles\MicrosoftVisualStudio10.0\boost_1_55_0] after download. (Here is my unzip directory).
(2) Run Bootstrap.bat generate Bjam.exe executable file
Implemented using the VS2010 command line, and later the VS2010 command line is used to compile the boost library. The steps are:
Click Start, All Programs--Microsoft Visual Studio 2010-->visualstudio tools--> Visual Studio 2010 command prompt.
Open the VisualStudio 2010 command prompt and enter the Boost decompression directory (D:\ProgramFiles\MicrosoftVisualStudio10.0\boost_1_55_0):
Run the Booststrap.bat application: Enter Bootstrap.bat [carriage return] to run.
After running, you can see the generated b2.exe and Bjam.exe in the Bootstrap.bat current directory. After the completion of the corresponding prompt, you can follow the instructions.
(3) Modify the User-config.jam file
user-config.jam The location of the file is in boost unzip directory boost_1_55_0\tools\build\v2 directory [ My decompression directory location is D:\ProgramFiles\MicrosoftVisualStudio10.0\boost_1_55_0\tools\build\v2 directory. ]
Open The User-config.jam file [Notepad available] and add the following [other content is blocked by default:
using msvc:10.0:: <compileflags>/wd4819 <compileflags>/d_crt_secure_no_deprecate < Compileflags>/d_scl_secure_no_deprecate <compileflags>/d_secure_scl=0; |
<compileflags> is separated by a space, and the ': ' and ':: ' formats are correct. The MSVC entry should be msvc:9.0 if the development environment is VS2008. Close the file after saving.
(4) Compile the library file with Bjam.exe
execute the following command in the Visual Studio 2010 Command Prompt Command Window [ you can command bjam–show-libraries to see which libraries must be compiled to use ]:
Bjam stage --toolset=msvc-10.0 --without-python--without-mpi--without-wave--without-graph--without-math- -without-serialization--stagedir= "D:\BOOST_1_55_0\BOOST_1_55_0\BIN\VC10" Link=static runtime-link=shared Threading=multi Debug Release |
stagedir= "D:\BOOST_1_55_0\BOOST_1_55_0\BIN\VC10" specifies the compiled library file storage directory
If the development environment is VS2008, the corresponding--toolset parameter value is msvc-9.0. After running this command, you can see that the Bin,bin.v2 file is generated under the specified directory F:\boost_1_54_0\boost_1_54_0, and then as you compile, there are more and more things in these two files.
If it is all compiled and the compiled library is placed in the specified directory, you can write the Bjam command like this:
Bjam stage--toolset=msvc-10.0--build-type=complete--stagedir= "D:\BOOST_1_55_0\BOOST_1_55_0\BIN\VC10" link=static runtime-link=shared Threading=multi Debug Release
Under the XP system, after compiling with VS2008, there are also hints for environment configuration.
Bjam The command and parameters are separated by a space between the parameters and parameters. Debug Release means that both the debug and release versions are generated.
The Bjam is used in the following form:
Bjam-- parameter 1- mode 1-- parameter 2- mode 2 parameter 3= mode 3 ... debug release
Parameters to add "--", parameter corresponding to the "-without-serialization" –without and serialization to add "-", the other parameters need to be set to the corresponding mode with "=".
Bjam.exe some of the parameters are explained as follows:
stage/install : Stage specifies boost c++ library installed in a subdirectory named stage, but also --stagedir Specify the installation path; install system-wide installation ( Windows The installation directory is c: \boost linux/usr/local --prefix pointed out. The stage indicates that only libraries (DLLs and Lib) are generated,and the install also generates an include directory with header text . "Unverified" --toolset: Specifies the compiler for C + + [VS2008 corresponds to--toolset=msvc-9.0,vs2010-- toolset=msvc-10.0] --build-type : How to create a library. By default, this option is set to minimal, which creates only the release version. It can be a problem for developers who want to build a debug version of their project with visual Studio or GCC. Because these compilers will automatically attempt to link the debug version of the boost C + + library, this will give you an error message. In this case, you should set the--build-type option to complete to generate both the debug and release versions of the boost C + + library, which will take longer, of course. Link : Create dynamic [Link=shared] or Static [Link=static] the library . Runtime-link: Specifies whether the C + + Runtime Library is a static [runtime-link=static] link or dynamic [runtime-link=shared] links Threading : Single [Threading=single]/ multithreaded [Threading=multi] compiled. Without/with : Choose which libraries are not compiled / compiled. |
The Jamroot file under the D:\Program Files\Microsoft Visual Studio 10.0\boost_1_55_0 root directory is a detailed usage note about Bjam.
There are not many libraries installed , if I want to use these libraries that are not installed in the future , then re-enter the VS2010 command line installation .
This process execution time is relatively long [do not install so many libraries OK, if they are installed then the time is really longer, feel that my computer is more than one hours online said, so choose what library will be used in the future to install the way to use Bjam.exe. But the better-equipped desktop spends less time, and a lot of strings appear in the command window. This scene reminds me of the Linux character interface that the sophomore started, and the scenes that operate under that interface are similar to this one, and I think the commands under the command line use the same format. You can check the usage of the Bjam specifically.
(5) VS2010 Boost library configuration
set an environment variable boost for boost, variable value:D:\boost_1_55_0\boost_1_55_0. The following settings are then made in the corresponding directories in the VS2010 project.
Right-click Items--Properties-->vc++ directory;
1. Add the Boost library file directory (that is, D:\BOOST_1_55_0\BOOST_1_55_0\BIN\VC10) to the Library directory (or into the D:\Program files\microsoft Visual Studio 10.0\vc\lib directory).
2. Place The D:\ProgramFiles\MicrosoftVisualStudio10.0\boost_1_55_0\boost directory (that is, the directory where the extracted boost1_55_0 contains the header file) into the D:\ Program Files\Microsoft The Visual Studio 10.0\vc\include directory).
if VS2008, the configuration steps are:
Open the VS2008 project, the tools----Project and Solution-->vc++ directory, and then select Include Files and library files in the upper-right corner (the directory that displays the following content).
(6) test
#include <boost/thread/thread.hpp> #include <iostream>void hello () {for (int i=0;i<30;i++) {std::cout << "Hello World, I ' m a thread!" <<std::endl;}} void Hello2 () {for (int i=0;i<30;i++) {std::cout<< "Hello world2222, I ' m a thread!" <<std::endl;}} int main () {Boost::thread thrd (&hello); Boost::thread Thrd2 (&hello2); Thrd.join (); Thrd2.join (); return 0;}
Boost library in Windows compilation and configuration (VS2010)