How to install the Boost library in Windows

Source: Internet
Author: User
Tags vc9

1. Overview

I plan to learn about the Boost library recently. Here I will record the method for installing the Boost library. IDE involves DEV C ++ and VS 2008.

2. Download

Direct download link: Refer to website.
SVN download link. The file is saved under "D: \ Boost". For more information, see "dig. I checked it online. Some people said that for Boost 1.46, if it is fully compiled, it may require 12-15 GB space, which is not surprising, although not compiled, it takes 3 GB.

3. VS2008 Boost library compilation (-vc9)

First, compile bjam and run bootstrap. bat-vc9 on the command line.
Then, compile the library. Run:

Bjam stage -- toolset = msvc-9.0 -- without-graph -- without-graph_parallel -- without-math -- without-mpi -- without-python -- without-serialization -- without-wave -- stagedir = "D: \ Boost \ bin \ vc9 "link = static runtime-link = shared threading = multi debug release
Bjam stage -- toolset = msvc-9.0 -- without-graph -- without-graph_parallel -- without-math -- without-mpi -- without-python -- without-serialization -- without-wave -- stagedir = "D: \ Boost \ bin \ vc9 "link = static runtime-link = static threading = multi debug release

It took about 50 minutes to compile and generated 30 3 MB files.

4. VS2008 Boost library Configuration

Tools-> Options-> Projects and Solutions-> VC ++ Directories
In Library files, add D: \ Boost \ bin \ vc9 \ lib
In Include files, add D: \ Boost \
Among them, the Library directory is the location where the previously compiled Library files are saved
The Include directory varies with different Boost versions. Now, you only need to specify D: \ Boost in version 1.47 to use SVN to download the Boost folder.

5. VS2008 Boost library Test

View Code

# Include "stdafx. h"
# Include <iostream>
# Include <boost/date_time/gregorian. hpp> using namespace std;
Using namespace boost;
Int _ tmain (int argc, _ TCHAR * argv [])
{
Cout <"Enter your birthday, format \" YYYY-MM-DD \":";
String strBirthday;
Cin> strBirthday;
Try
{
Gregorian: date birthday (gregorian: from_simple_string (strBirthday ));
Gregorian: date today (gregorian: day_clock: local_day ());
Gregorian: days days_alive = today-birthday;
If (days_alive <gregorian: days (0 ))
{
Cout <"Wow, you can use your computer before you are born." <Endl;
}
Else
{
Cout <"you have appeared in this world:" <days_alive.days () <"days" <Endl;
}
}
Catch (Gregorian: bad_year & E)
{
Cerr <E. What () <Endl;
}
Catch (gregorian: bad_day_of_month & e)
{
Cerr <e. what () <endl;
}
Catch (gregorian: bad_day_of_year & e)
{
Cerr <e. what () <endl;
}
Catch (...)
{
Cerr <"Error! "<Endl;
}
System ("pause ");
Return 0;
}

6. dev c ++ Boost library Compilation

First, set the gcc environment variable. Right-click my computer and choose Properties menu item. In the displayed dialog box, select the Advanced page and click Environment Variables. After the following settings, select PATH, and then click the Edit button, add the DEV-C ++ compiler PATH, such as C: \ Program Files \ DEV-CPP \ Bin, the PATH is separated by a semicolon. Click OK to save the settings.
Then, compile bjam and run bootstrap. bat-gcc.
Next, compile the boost Library:

Bjam stage -- toolset = gcc -- without-graph -- without-graph_parallel -- without-math -- without-mpi -- without-python -- without-serialization -- without-wave -- stagedir = "D: \ Boost \ bin \ gcc "link = static runtime-link = shared threading = multi debug release
Bjam stage -- toolset = gcc -- without-graph -- without-graph_parallel -- without-math -- without-mpi -- without-python -- without-serialization -- without-wave -- stagedir = "D: \ Boost \ bin \ gcc "link = static runtime-link = static threading = multi debug release

7. dev c ++ Boost library Configuration

Add D: \ Boost to Toos-> Compiler Options-> Directories-> C ++ Include.
8. dev c ++ Boost library Test

First, all functions in the header file can be used as long as the header file is included.

View Code

# Include <boost/lambda. hpp>
# Include <iostream>
# Include <iterator>
# Include <algorithm>
Using namespace std;
Int main ()
{
Using namespace boost: lambda;
Typedef istream_iterator <int> in;
For_each (in (cin), in (), cout <(_ 1*3) <"");
Return 0;
}

Second, you need to create a project, instead of compiling a single c ++ file, because in dev c ++, linker parameters can be set only in the project. After a project is created, the "Project" --> "Project Options" --> "Parameters" tab ---> Add: "-lboost_regex-mt" in the linker box to tell linker when it is linked, link to the regex library.

View Code

# Include <boost/regex. hpp>
# Pragma comment (lib, "D: \ boost \ boost_1_42_0 \ stage \ libboost_regex-meg34-mt.lib ")
# 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 [1] <"" <matches [2] <std: endl;
}
Return 0;
}

9. References

Boost download install build configuration User Guide (including Windows and Linux) http://kb.cnblogs.com/a/1485890/
Boost 1.38 http://blog.csdn.net/wrx_2009/archive/2009/06/04/4242841.aspx compiled in VS2008
VS2008 Team System install Boost library http://www.cookbus.com/show-121-1.html
Http://blog.csdn.net/suwei19870312/archive/2011/03/13/6246400.aspx of boost Installation Process in DevC ++

Related Article

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.