首次接触Boost过程

来源:互联网 发布:1000以内的完数c语言 编辑:程序博客网 时间:2024/05/16 15:59

早听说boost的大名。今天尝试了一下,期间仅遇到了一个小问题,网上搜索无果后,自己尝试成功解决,望可以帮助其他人。

在官网下载下来后http://www.boost.org/,版本是1.55.0,废话不说,开搞。

按照官网上的Get Started步骤,一步步弄。在vs下进行

首先,解压。------时间不短。

然后第一个程序成功,很容易。就是配置配置工程属性,然后调用boost里东西。只要不是英语文盲都应该没问题。

然后到了下一步,

Prepare to Use a Boost Library Binary。这是干什么呢?If you want to use any of the separately-compiled Boost libraries, you'll need to acquire library binaries.由于Boost中有一些库是需要单独构建的。好的没问题按照步骤来

If you wish to build from source with Visual C++, you can use a simple build procedure described in this section. Open the command prompt and change your current directory to the Boost root directory. Then, type the following commands:

bootstrap.\b2

The first command prepares the Boost.Build system for use. The second command invokes Boost.Build to build the separately-compiled Boost libraries. Please consult theBoost.Build documentation for a list of allowed options.

这里我直接到了boost目录中运行的bootstrap.bat,然后才在命令行里敲 .\b2

本以为,这个步骤也是很easy,没想到时间还挺长。然后楼主很兴奋的关掉了控制台。没有注意的其中的内容,这位我之后的问题埋下伏笔。然后测试官网给的第二个例子。哎呀问题来了。

  1. 在Right-click example in the Solution Explorer pane and selectProperties from the resulting pop-up menu
  2. In Configuration Properties > Linker > Additional Library Directories, enter the path to the Boost binaries, e.g.C:\Program Files\boost\boost_1_55_0\lib\.
  3. From the Build menu, select Build Solution.

在以上步骤之后,(在第一个范例中我已更改了包含目录)也就是修改了附加库目录之后。运行程序。

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

其中boost::regex就是一个需要单独built的库。

我受到了一个链接错误

LINK : fatal error LNK1104: 无法打开文件“libboost_regex-vc110-mt-gd-1_55.lib”哎?再次检查自己之前的步骤,没有问题呀。然后百度、google一顿搜。

方法都试了不行。然后我又尝试build boost。一段时间等待之后。我看到了控制台最后的内容。大意就是恭喜成功。然后给了各路径

C:\Users\Mr.Guo\Downloads\boost_1_55_0\stage\lib

我类个去,这东西原来没有的呀。然后链接附加库目录修改为改路径。程序运行成功


希望自己能够坚持下去,钻研一下这个Boost。



原创粉丝点击