How to use the Boost C + + library under Windows

Source: Internet
Author: User
Tags connect

I'm using VC8.0 and Boost_1_35_0. It's okay to recompile boost yourself, but I use the

Http://www.boostpro.com/products/free

The installation tool provided Boostpro 1.35.0 Installer (192K. exe). I strongly recommend using this tool to install the Boost library and source files under Windows.

1 Use the Boost_1_35_0_setup.exe tool to download the Boost library, select the package you want (the type is always mutilthread and Mutithread Debug), automatically installed after downloading. I use VC8.0 boost_1_35_0 to install in E:\boost. I mainly introduce the 2 libraries that need to be compiled before using regex and signals.

2 I set up a console project under the VC8.0, and added a VC inclusion directory for the project: E:\BOOST\BOOST_1_35_0, and Library directory: E:\boost\boost_1_35_0\lib. You do not need to specify which library to link to because the system will automatically find it.

3 Note that I do not use the dynamic link library, because a bunch of warnings, let me fear. So I use a static connection library, which is a library with a libboost-xxx style before the name. For example, to use (note the exact same name as the following):

Debug under:

Libboost_signals-vc80-mt-gd-1_35.lib

Libboost_regex-vc80-mt-gd-1_35.lib

Release under:

Libboost_signals-vc80-mt-1_35.lib

Libboost_regex-vc80-mt-1_35.lib

And the project properties of VC are:

Debug: Multithreaded Debug DLL (/MDD), not Unicode

Release: Multithreaded DLL (/MD), not Unicode

In particular, be aware that when using a tool to download, always download:

Mutilthread and Mutithread Debug

The advantage of this is that we are linked to the static boost library, so no boost DLL is needed. Don't choose to use Boost's dynamic library in order to covet the small size of the Run-time package, at least I shudder at the warning.

Here is a small example, no warning, everything is on schedule:

///////////////////////////////////////////////////////////////////////////////
Main.cpp
//
Using the Boost C + + standard library
//
//
2008-7-10 Cheungmine
//
///////////////////////////////////////////////////////////////////////////////
#include <boost/lambda/lambda.hpp>
#include <boost/regex.hpp>

#include <iostream>
#include <cassert>

#include <boost/signals.hpp>

struct Print_sum {
void operator () (int x, int y) const {std::cout << x+y << Std::endl;}
};

struct Print_product {
void operator () (int x, int y) const {std::cout << x*y << Std::endl;}
};

//
Main program
//
int main (int argc, char** argv)
{
boost::signal2<void, int, int, boost::last_value<void>, std::string> Sig;

Sig.connect (Print_sum ());
Sig.connect (Print_product ());

SIG (3, 5);

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;
}

return 0;
}

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.