The configuration and use of Boost (VS2010)

Source: Internet
Author: User
Tags assert

The boost library is a portable, source-coded C + + library that serves as a fallback to the standard library and is one of the development engines of the C + + standardization process. The Boost library is launched by members of the C + + Standard Committee Library team, some of which are expected to be content in the next-generation C + + standard library. The impact in the C + + community is very large, is the absolute "quasi" standard library. Thanks to its cross-platform emphasis, the emphasis on standard C + + has nothing to do with writing platforms. Most boost library features need only include the corresponding header files, and a few (such as regular expression libraries, file system libraries, etc.) require a link library. But there are also a lot of things that are experimental in boost and need to be cautious in practical development.

The development of boost libraries uses many modern C + + programming techniques, content covers string processing, regular expression, container and data structure, concurrent programming, functional programming, generic programming, design pattern implementation and many other fields, greatly enriching the function and expressiveness of C + +, can make C + + software development More concise, elegant , flexible and efficient.

Boost's official download address: http://sourceforge.net/projects/boost/files/boost/

VS2010 Configure boost Programming environment

The first step: Download boost. I originally downloaded the name is called Boost_1_55_0.

Step two: After downloading I extracted the file into the E:/boost directory. Step three: Start the-> program->microsoftvisual Studio 2010->visual Studio tools->visual Studio Command Prompt (2010) to open a console.

Fourth Step: CD e:\boost\boost_1_55_0, switch the current operation directory to the Boost directory folder to facilitate the execution of the program in the folder.

Fifth Step: Execute the Bootstrap.bat program, enter at the command line: Bootstrap.bat

Sixth step: After the completion of the fifth step will generate two programs, respectively, B2.exe and Bjam.exe.

Seventh Step: Modifying User-config.jam files

The location of the User-config.jam file is located in the Tools\build\v2 directory of the Boost decompression directory [my unzipped directory location is E:\boost_1_55_0\tools\build\v2].

Open the User-config.jam file [available Notepad] and add the following [other content is blocked by default]:

Using msvc:10.0:: <compileflags>/wd4819 <compileflags>/d_crt_secure_no_deprecate <compileflag S>/d_scl_secure_no_deprecate <compileflags>/d_secure_scl=0;

<compileflags> separated by a space, the above ': ' and ':: ' The format is correct. If the development environment is VS2008, the MSVC entry should be msvc:9.0.

Close the file after saving.

Step Eighth: compile the Build library file with Bjam.exe.

Also execute the following command in the Visual Studio Command prompt Commands window

[[ You can use the command bjam–show-libraries to see which libraries must be compiled before ]]

Bjam stage--toolset=msvc-10.0--without-python--without-mpi--without-wave- Without-serialization--stagedir= "F:\BOOST_1_55_0\BOOST_1_55_0\BIN\VC10" Link=static runtime-link=shared threading =multi Debug Release

Of course, the above command does not compile like python,mpi,graph libraries.

If you want to compile all, you can use the following command:

b2--toolset=msvc-10.0--build-type=complete Stage or (2) bjam.exe--toolset=msvc-10.0--build-type=complete

If the development environment is VS2008, the corresponding--toolset parameter value is msvc-9.0. After you run this command, you can see that the Bin,bin.v2 file is generated under the specified directory E:\boost\boost_1_55_0\boost_1_55_0, and then as you compile, there are more and more things inside these two files.

If you are compiling all, and you put the compiled library in the specified directory, you can write the Bjam command like this:

Bjam stage--toolset=msvc-10.0--build-type=complete--stagedir= "E:\BOOST\BOOST_1_55_0\BOOST_1_550\BIN\VC10" Link=static runtime-link=shared threading=multi Debug Release

Under the XP system, the VS2008 is compiled with a full set of environment configuration prompts.

The Bjam command and between parameters and parameters and parameters are separated by a space. Debug release means that both the debug and release versions are generated.

Bjam is used in the form of:

Bjam--Parameter 1-mode 1--Parameter 2-mode 2 Parameter 3 = Mode 3 ... debug release

parameter to add "--", the corresponding items such as "-without-serialization" –without and serialization to add "-", other parameters need to be set to the corresponding pattern with "=".

The Bjam.exe partial parameters are explained as follows:

stage/install : stage Specifies that the Boost c++ library is installed under a subdirectory named stage, but also --stagedir Specifies the installation path, install is installed on a system-wide (Windows installation directory is C:\Boost, while Linux is/usr/local), and the destination directory can also be indicated by --prefix . The

Stage represents only building libraries (DLLs and Lib), and install also generates include directories that contain header files. "Unauthenticated"

--toolset : Specifies C + + compiler [VS2008 corresponding--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 is to create only the release version. This may 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 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, and of course, the time will be longer.

Link : Create dynamic [  link=shared] or a static [link=static] library.

Runtime-link : Specifies whether the C + + Run-time library is a static [runtime-link=static] link or a dynamic [runtime-link=shared] link

Threading : Single [  threading=single]/multithreaded [  Threading=multi] compiled.

without/with : Select which libraries are not compiled/compiled.

There are not many cubby installed, if I want to use these not installed these libraries, then re-enter the VS2010 command line installation.

The process of execution time is relatively long [do not install so many libraries okay, if the installation of the time is really longer, I feel that my computer is more than one hours on the internet, so the choice will be used to what library to install the way to use Bjam.exe. However, it takes less time to configure a better desktop, and a large number of strings appear in the command window. This scene reminds me of the Linux character interface that I started with sophomore, and the scene that operates under that interface is similar to this one, and I think the commands on the command line use the same format . You can specifically check the usage of Bjam.


After completing the above steps, the VS2010 can be configured for the Boost library.

An environment variable is also set up for boost, modeled after the ACE installation mode. Then in the VS2010 project the corresponding directory to the following settings [this process, if not clear, look at the ACEVS2010 configuration process]. Simply add the Boost directory above the bin, boost, and more to the path path, as well as the environment variable [boost] values that are set up.

Include directory: $ (BOOST)

Library Directory: $ (BOOST) \bin\vc10\lib

If it is VS2008, the configuration steps are:

Open the VS2008 project, the tools--> option--> the project and solution-->vc++ directory, and then select the Include file and library file in the upper-right corner (the directory that displays the following content).

Add a row to the include file: $ (BOOST)

Add a row to the library file: $ (BOOST) \bin\vc08\lib

Create a project with the additional include directory: D:\BOOST_1_55_0; the additional library directory is: D:\boost_1_55_0\stage\lib.

if it is in 2010 environment this step, in oneself to establish the project--> right key Select "attribute"-->vc++ directories to fill in the corresponding path

The two steps of my configuration are: (1) E:\boost_1_55_0 (2) E:\boost_1_55_0\stage\lib

by completing the steps above, you can use the Boost library in VS2010. The test code is as follows:

#include <iostream>
#include <boost/regex.hpp>
using namespace std;
int main ()
{
    Boost::regex reg ("\\d{3}" ([a-za-z]+). \\d{2}| N/a) \\s\\1 ");
    std::string correct= "123Hello N/a Hello";
    std::string incorrect= "123Hello hello";

    ASSERT (Boost::regex_match (correct,reg) ==true);
    ASSERT (Boost::regex_match (incorrect,reg) ==false);
    cout<< "Hello Boost!" <<endl;
}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.