vs2010下 boost库的使用笔记(一)

来源:互联网 发布:淘宝返利网是什么意思 编辑:程序博客网 时间:2024/05/16 06:27
下载boost_1_46_1库http://www.boost.org/users/download/(目前的版本为:1_55_0)
我把它解压缩到了E:/mylib/boost_1_46_1下面。
在vs上面 文件>新建 > 项目…
在左边的已安装模板中选Visual C++ > Win32.
然后再右边的面板中选Win32控制台应用程序。
下面的名称输入 example 然后 确定 完成。
项目> example属性… >配置属性 >C/C++ >常规> 附加包含目录  输入Boost的目录路径
我这里是E:/mylib/boost_1_46_1
在 example属性… >配置属性 >C/C++> 预编译头 >预编译头 替换使用(/Yu)不使用预编译头(第一次设置的时候,这里没有内容。我是保留#include "stdafx.h" 编译之后,再次设置的时候,发现了这个选项。如此设置后,我注释掉了#include "stdafx.h")
 复制代码到example.cpp文件
[cpp] view plaincopy
  1. #include <boost/lambda/lambda.hpp>  
  2. #include <iostream>  
  3. #include <iterator>  
  4. #include <algorithm>  
  5. int main()  
  6. {  
  7.     using namespace boost::lambda;  
  8.     typedef std::istream_iterator<int> in;  
  9.     std::for_each(  
  10.         in(std::cin), in(), std::cout << (_1 * 3) << " " );  
  11. }  
 
生成 >生成解决方案 
调试> 启动调试
控制台界面出现 
输入 1 2 3
输出 3 6 9

前面已经简单的使用了boost库,但是如果想要使用 

  • Boost.Filesystem
  • Boost.GraphParallel
  • Boost.IOStreams
  • Boost.MPI
  • 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

等,还是的编译一下,要不然就会出现如下的错误“LINK : fatal error LNK1104: 无法打开文件“libboost_regex-vc100-mt-gd-1_46_1.lib”

 

打开命令行窗口 

切换到 boost库的根目录。

我的是E:/mylib/boost_1_46_1

输入bootstrap

然后有几行输出

再输入./bjam

类库编译开始(这个真是个漫长的过程 ………………)

哎 等了 1个小时了 

还得等 

再编译一会儿吧

 

N久之后 编译好了

 

 

ln-NT stage/lib/libboost_unit_test_framework-vc100-mt.lib

"NT symlinks not supported yet, making copy"

已复制         1 个文件。

ln-NT stage/lib/libboost_thread-vc100-mt.lib

"NT symlinks not supported yet, making copy"

已复制         1 个文件。

ln-NT stage/lib/libboost_wave-vc100-mt.lib

"NT symlinks not supported yet, making copy"

已复制         1 个文件。

...updated 786 targets...

 

The Boost C++ Libraries were successfully built!

 

The following directory should be added to compiler include paths:

 

    E:/mylib/boost_1_46_1

 

The following directory should be added to linker library paths:

 

    E:/mylib/boost_1_46_1/stage/lib

 

 

用如下代码替换上一次的那个example.cpp的内容

[cpp] view plaincopy
  1. #include <boost/regex.hpp>  
  2. #include <iostream>  
  3. #include <string>  
  4. int main()  
  5. {  
  6.     std::string line;  
  7.     boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );  
  8.     while (std::cin)  
  9.     {  
  10.         std::getline(std::cin, line);  
  11.         boost::smatch matches;  
  12.         if (boost::regex_match(line, matches, pat))  
  13.             std::cout << matches[2] << std::endl;  
  14.     }  
  15. }  
 

在工程中添加库引用

属性>连接器>常规 >  附加目录库 这里写入 E:/mylib/boost_1_46_1/stage/lib

编译

运行

输入

To: George ShmidlapFrom: Rita MarloweSubject: Will Success Spoil Rock Hunter?
输出
Will Success Spoil Rock Hunter?
一个简单的正则表达式编译成功。
至此,boost库编译成功。

 

  1. In Configuration Properties > Linker > Additional Library Directories, enter the path to the Boost binaries, e.g. C:/Program Files/boost/boost_1_46_1/lib/.
  2. From the Build menu, select Build Solution.

原创粉丝点击