linux/ubuntu install boost .

来源:互联网 发布:excel数据误删怎么恢复 编辑:程序博客网 时间:2024/05/17 22:18
安装所有开发所需编译工具 gcc g++等等
sudo apt-get install build-essential


然后 安装库

sudo apt-get install libboost-dev libboost-dbg libboost-doc bcp libboost*
或者

sudo apt-get install libboost-all-dev, 安装即可。


也可以源码安装

下载boost库

         这个我就不说啥了,去官网看一下就能下到: www.boost.org

2.cd到想安装的目的目录,执行

tar --bzip2 -xf /"boost库存放目录"/boost_1_36_0.tar.bz2

3.boost库

boost_1_36_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. bjam, quickbook, bcp
   more/ ..........................Policy documents, etc.
   doc/ ...............A subset of all Boost library docs

注:

  1. 在文档中提到boost根目录 (通常是 /usr/local/boost_1_36_0)时,采用$BOOST_ROOT .

  2. 编辑任何boost文件时,需要在#include 路径中包含boost/子目录。

  3. 所有的boost头文件都有hpp扩展名, 在boost目录下,所以在#include 中应该类似以下:

    #include whatever.hpp>

    或者#include "boost/whatever.hpp" 

  4. 不用在意doc文件夹下的内容,里面只是一些boost文档。找东西时候,可以通过libs/index.htm

1、下载

  首先,请仔细阅读http://www.boost.org/more/getting_started.html,英语不好的,这里有一份中文版的: http://blog.csdn.net/goodboy1881/archive/2006/03/27/640004.aspx

  现在上下载整理好的boost_1_47_0/源码发行版,

2、安装

  首先解包,注意不要破坏其目录结构,下文以$BOOST代替解包后boost所在的目录,譬如,我是从sourceforge上下的boost_1_47_0.tar.gz,解包后的路径是~/opt/boost_1_47_0

  然后从源码包编译出BJam工具。这是因为Boost 使用自己的编译系统BJam来保证Boost在任何平台上都能用bjam编译。步骤如下:

  $ cd boost_1_47_0/tools/build/v2/engine/
  $ ./build.sh

build脚本执行完毕后,会在当前目录的binlinuxx86子目录下生成bjam,将之mv到$BOOST下。

  现在可以编译安装boost库了:

  若采用默认编译安装,安装至/usr/local下,只需 ./bjam "-sTOOLS=gcc" " install即可。
  若指定编译安装目录,只需./bjam "-sTOOLS=gcc" "--includedir=$includepath" "--libdir=$libpath" install即可。
  若不全部编译安装,只需./bjam "-sTOOLS=gcc" "--with-"即可,譬如我只是想用regex库,./bjam "-sTOOLS=gcc" "--with-regex"就可以了。

3、试用
  
  regex如何使用,这是近期的学习内容。现在只需找份代码,测试一下安装的regex能不能用,就可以了。从《Beyond the C++ Standard Library: An Introduction to Boost》书中找到一份regex应用代码如下:
//testRegex.cpp
#i nclude <iostream>
#i nclude <string>
#i nclude <boost/regex.hpp>

int main()
{
  std::cout << "Enter a regular expression:/n";
  std::string s;
  std::getline(std::cin, s);
  try
  {
    boost::regex reg(s);
    std::cout << "Enter a string to be matched:/n";
    std::getline(std::cin,s);
    if (boost::regex_match(s,reg))
      std::cout << "That's right!/n";
    else
      std::cout << "No, sorry, that doesn't match./n";
  }
  catch(const boost::bad_expression& e)
  {
  std::cout << "That's not a valid regular expression! (Error: " << e.what() << ") Exiting.../n";
  }
  return 0;
}
编译:
g++ testRegex.cpp -I /usr/local/include/boost_1_33_1 -L /usr/local/lib -lboost_regex-gcc -o testRegex

运行:
./testRegex

  可能会出错,出错信息是说有动态库文件找不到,这是因为咱编译安装的regex库是放在 /usr/local/lib中的,而系统执行程序时,默认的库搜索路径是/usr/lib,所以提示找不到。只需要在/usr/lib中建立一些指向 /usr/local/lib中的boost_regex库文件的连接即可。可能还有更好的方法,比如修改系统运行程序时的默认搜寻路径,不过我不会改,日后再说。

  做了上面的工作后,testRegex就可以运行了,测试一下执行情况,如下面的输入与输出:
Enter a regular expression:

/d{5}

Enter a string to be matched:

12345

That's a right!

  OK了,剩下的事情就是学习正则表达式了。

http://blog.csdn.net/tykgls/article/details/6822038
原创粉丝点击