cygwin下boost编译安装

来源:互联网 发布:孤岛惊魂3低配置优化 编辑:程序博客网 时间:2024/04/29 11:05

1、下载boost_1_40_0.tar.bz2  (http://sourceforge.net/projects/boost/files/boost/)
2、解压tar --bzip2 -xf /home/Administrator/boost_1_40_0.tar.bz2
3、有些库文件不用编译就能工作:
  Boost.DateTime has a binary component that is only needed if you're using its to_string/from_string or serialization features, or if you're targeting Visual C++ 6.x or Borland.
  Boost.Graph also has a binary component that is only needed if you intend to parse GraphViz files.
  Boost.Test can be used in “header-only” or “separately compiled” mode, although separate compilation is recommended for serious use.
  
  有些库文件一定要编译:
  Boost.Filesystem
  Boost.IOStreams
  Boost.ProgramOptions
  Boost.Python (see the Boost.Python build documentation before building and installing it)
  Boost.Regex
  Boost.Serialization
  Boost.Signals
  Boost.System
  Boost.Thread
  Boost.Wave
  
4、试着编写一个不需要编译库的程序:
//////////////////////////////////////////////////////
  #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) << " " );
  }
///////////////////////////////////////////////////////////  
   example.cpp c文件如上面。把他保存在/home/Administrator下面。
  
   g++ -I boost_1_40_0 example.cpp -o example

  运行   $echo 1 2 3 | ./example
  
5、编译库文件:

  $ cd path/to/boost_1_40_0
  $ ./bootstrap.sh
  产生bjam文件
  
  $ ./bjam install
  安装头文件 时间很久
  
  将会把boost头文件拷贝到/usr/local/include
  
6、试着编写一个需要编译库的程序:

  #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;
      }
  }
  
  编译 $g++ example1.cpp -o example1 -L/home/Administrator/boost_1_40_0/stage/lib -lboost_regex
  
  如果把-lboost_regex.a 文件拷到/lib目录下
  只要 $g++ example1.cpp -o example1 -lboost_regex
  
7、试过OK。哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈
  

原创粉丝点击