一、下載boost
Download .
在boost庫安裝目錄中解壓
tar --bzip2 -xf /path/to/boost_1_79_0.tar.bz2
二、boost發(fā)行版
目錄結(jié)構(gòu):
* boost_1_79_0/ .................The “boost root directory”
* index.htm .........A copy of www.boost.org starts here
* boost/ .........................All Boost Header files
* libs/ ............Tests, .cpps, docs, etc., by library
* index.html ........Library documentation starts here
* algorithm/
* any/
* array/
…more libraries…
* status/ .........................Boost-wide test suite
* tools/ ...........Utilities, e.g. Boost.Build, quickbook, bcp
* more/ ..........................Policy documents, etc.
* doc/ ...............A subset of all Boost library doc
- ** $BOOST_ROOT**通常是boost root directory (often /usr/local/boost_1_79_0)
- 因?yàn)樗械腷oost頭文件都有.hpp擴(kuò)展名,并且位于boost根目錄的boost /子目錄中,所以boost #include指令可以:
#include <boost/whatever.hpp>或
#include "boost/whatever.hpp" - 不要被doc/子目錄分心;它只包含boost文檔的一個(gè)子集。如果您想要查找全部內(nèi)容,請(qǐng)從libs/index.html開始。
三、構(gòu)建boost
1、大部分boost不需要構(gòu)建,是head-only的庫。
2、需要編譯的庫有:
- Boost.Chrono
- Boost.Context
- Boost.Filesystem
- Boost.GraphParallel
- Boost.IOStreams
- Boost.Locale
- Boost.Log (see build documentation)
- Boost.MPI
- Boost.ProgramOptions
- Boost.Python (see the Boost.Python build documentation before building and installing it)
- Boost.Regex
- Boost.Serialization
- Boost.Thread
- Boost.Timer
- Boost.Wave
3、一些庫有可選的單獨(dú)編譯的二進(jìn)制文件:
- Boost.Graph also has a binary component that is only needed if you intend to parse GraphViz files.
- Boost.Math has binary components for the TR1 and C99 cmath functions.
- Boost.Random has a binary component which is only needed if you're using <tt class="docutils literal">random_device</tt>.
- Boost.Test can be used in “header-only” or “separately compiled” mode, although separate compilation is recommended for serious use.
- Boost.Exception provides non-intrusive implementation of exception_ptr for 32-bit _MSC_VER==1310 and _MSC_VER==1400 which requires a separately-compiled binary. This is enabled by #define BOOST_ENABLE_NON_INTRUSIVE_EXCEPTION_PTR.
- Boost.System is header-only since Boost 1.69. A stub library is still built for compatibility, but linking to it is no longer necessary.
四、示例
#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) << " " );
}
c++ -I path/to/boost_1_79_0 example.cpp -o exampleecho 1 2 3 | ./example-
結(jié)果如下:
運(yùn)行結(jié)果.png
