Boost-Getting Started Guide and boost Getting Started Guide

Source: Internet
Author: User
Tags visual studio 2010

Boost-Getting Started Guide and boost Getting Started Guide


What is boost

The boost library is an open-source and free third-party library. It is a very good library and one of the best practices of the C ++ standard. Therefore, it is often used for commercial development. Therefore, if you are engaged in C ++ and have never heard of or used boost, you will be out and think about whether you cannot keep up with the pace of technology. Haha ......

For the status of boost, you can refer to its official documentation:

We aim to establish "existing practice" and provide reference implementations so that Boost libraries are suitable for eventual standardization. ten Boost libraries are supported in the C ++ Standards Committee's Library Technical Report (TR1) and in the new C ++ 11 Standard. C ++ 11 also includes several more Boost libraries in addition to those from TR1. More Boost libraries are proposed for standardization in C ++ 17.

We are committed to establishing (C ++ standard) "Existing practices" and Reference implementations, so boost libraries are applicable to the final standards. 10 boost libraries have been included in the library technical report (TR1) of the C ++ Standards Committee and the new C ++ 11 standard. In addition to the several libraries obtained from TR1, the C ++ standard also contains several additional boost libraries. More boost libraries may be used in the C ++ 17 standard.

 

Boost library usage

The following describes how to use it on the windows platform. The developed IDE is VS2010.

Download boost Library

You can go to its official http://www.boost.org to find the latest version of boost, download. You can also download the boost: http://www.boost.org/users/history/version_10957_0.htmlof 1.57.0 at this link.


Boost directory structure

Boost_000057_0 \...................................... ...... boost root directory

A copy of the instruction manual in index.htm Workshop

Boost \...................................... ............... all Boost header files

Lib \...................................... ..................... pre-compiled binary Library

Libs \...................................... ................... tests ,. cpps, docs, etc ., by library

Index.html ........................................ homepage of Boost Library User Manual

Algorithm \

Any \

Array \

... More databases...

Status \...................................... ............ boost-wide test package

Tools \...................................... .............. common tools, such. boost. build, quick query manual, bcp

More \...................................... ............. legal Terms

Doc \...................................... ................. A subset of the Boost library documentation

 

Introduce boost in the project

1. You only need to extract the downloaded boost package without any installation. Assume that your boost library is decompressed in the E: \ C ++ Workspace \ boost_000057_0 directory.

2. Create an empty project under VS2010 (I created a Win32 Console Application project, assuming the project name is BoostTest ).

3. right-click your project name, select Properties, and select Configuration Properties> C/C ++> General in the displayed dialog box, in Additional Include Directories, enter the boost root directory path extracted in step 1 (for example, E: \ C ++ Workspace \ boost_1_57_0)

4. Replace the content in BoostTest. cpp with the following test code:

#include "stdafx.h"#include <boost/lambda/lambda.hpp>#include <iostream>#include <iterator>#include <algorithm>int main(){using namespace boost::lambda;typedef std::istream_iterator<int> in;std::for_each(in(std::cin), in(), std::cout << (_1 * 3) << " " );}


 

4. compile your project BoostTest and run it (F5) after the compilation is successful ). In the pop-up console dialog box, Enter 2 4 6 and press Enter. The result of 6 8 12 is displayed, indicating that the test is successful and boost can be used normally. Press Ctrl + C to end the input.

Compile a binary boost Library

If you want to use any separately compiled Boost library, you need to obtain the binary library file. The process of compiling a binary library from the source code using Visual C ++ is as follows:

Open the Command Prompt console in VS2010: Windows Start Menu \ Microsoft Visual Studio 2010 \ Visual Studio Tools \ Visual Studio 2005 Command Prompt, use the cd command to locate the current directory to the Boost root directory (E: \ C ++ Workspace \ boost_000057_0). Enter the following two commands:

Compile command 1:

Bootstrap

. \ B2

 

The first command (bootstrap) will execute bootstrap. bat script is used to prepare the Boost to be used. build the program; the second command (. \ b2) is to call Boost. build the program to Build an independently compiled Boost library.

 

Enter the First Command (bootstrap) and wait for a short time. When the following prompt appears, it indicates that the command has been executed.

 

At this time, the Boost root directory will have four more files:

B2.exe: Boost. Build program, used to compile a binary Boost Library

Bjam.exe: Boost. Build program, used to compile a binary Boost Library

Bootstrap. log: logs recorded when the preceding two commands are executed.

Project-config.jam: Preparation Parameters for Boost. Build

B2.exe unzip bjam.exe the two exetries are the same. bjam.exe is an old version and b2 is an upgraded version of bjam.

 

Enter the second command (. \ b2) for compilation. The entire compilation process may take about an hour. Please wait patiently. After compilation is successful, the following prompt is displayed:

 

At this time, there will be more lib folders under your Boost root directory (The author is in. \ stage \ lib, which may be different on each computer or platform. Take the last prompt of the command line as the standard, for example,). This is the compiled Boost static library and dynamic library.

 

Compile command 2:

Bootstrap

B2 -- build-dir =. \ lib toolset = msvc-10.0 -- build-type = complete stage

 

After compiling with the compilation command, the following error is reported during the link test:

Error LNK2038: mismatch detected for '_ MSC_VER': value '000000' doesn' t match value '000000' in BoostTest. obj

Error LNK2038: mismatch detected for '_ MSC_VER': value '000000' doesn' t match value '000000' in BoostTest. obj

Error LNK2038: mismatch detected for '_ MSC_VER': value '000000' doesn' t match value '000000' in BoostTest. obj

Error LNK2038: mismatch detected for '_ MSC_VER': value '000000' doesn' t match value '000000' in BoostTest. obj

Error LNK2038: mismatch detected for '_ MSC_VER': value '000000' doesn' t match value '000000' in BoostTest. obj

Error LNK2038: mismatch detected for '_ MSC_VER': value '000000' doesn' t match value '000000' in BoostTest. obj

Error LNK1104: cannot open file 'libboost _ regex-vc100-mt-gd-1_57.lib'

 

But I only find the corresponding libboost_regex-vc120-mt-1_57.lib and libboost_regex-vc120-mt-gd-1_57.lib under the \ stage \ lib directory.

I checked the information online and said that the compiled Boost library is VC ++ 11. It must be supported on VS2012, but not VS2010. Therefore, you need to reset the option to specify the compiler version.

In the preceding command, the First Command (bootstrap) has the same meaning as the one in the compilation command, and the second command b2 -- build-dir =. \ lib toolset = msvc-10.0 -- build-type = complete stage has the following meanings:

-- Build-dir: the working directory used to store intermediate files when the Boost library is compiled

Toolset = msvc-10.0 toolset is a collection of C ++ compilers, msvc-10.0 represents Microsoft VC ++ 10.0 compiler, VS2010 support.

-- Build-type = complete stage "-- build-type = complete" causes Boost. Build to compile all supported Boost libraries.

 

 

 

Verify Boost Library

To verify the static library compiled above, we can use a simple "topic extraction" program for testing.

 

1. you have created a BoostTest project in "introduce boost in Project", right-click your project name, and select Properties ), in the displayed dialog box, select Configuration Properties> Linker> General, and enter the path of the static Library compiled above in Additional Library Directories (such as E: \ C ++ Workspace \ boost_000057_0 \ stage \ lib)

2. Replace the content in BoostTest. cpp with the following code:

#include "stdafx.h"#include <boost/regex.hpp>#include <iostream>#include <string>int main(){std::string line;boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );while (std::cin){std::getline(std::cin, line);boost::smatch matches;if (boost::regex_match(line, matches, pat))std::cout << matches[2] << std::endl;}}
 

3. Build your project

In the hosts file.

To: George Shmidlap

From: Rita Marlowe

Subject: Will Success Spoil Rock Hunter?

---

See subject.

 

5. Open the command prompt and locate the current directory to the Debug directory (for example, E: \ C ++ Workspace \ VS2010 \ BoostTest \

Debug), enter BoostTest.exe <subject.txt. Will the topic of the text be Success Spoil Rock Hunter? If the following result is displayed, the verification is successful.

 

 

For more information, see:

Http://www.boost.org/doc/libs/1_57_0/more/getting_started/windows.html#get-boost

Http://www.cnblogs.com/zhcncn/p/3950477.html

 

 

If you have any questions or thoughts, please give feedback in the comments. Your feedback is the best Reviewer! Due to my limited technical skills and capabilities, if this blog post contains errors or deficiencies, please forgive me and give your valuable suggestions!

 

 

 

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.