一、背景

最近在一周在做自然场景中图像文本检测和识别相关的工作,图像中文本检测阶段完成80%,识别部分准备用一下谷歌的TensorFlow框架。考虑到,后期用于训练图像C++代码部分会用到boost库,所以今天就试着下载和编译一下boost.

二、编译步骤

  1. ​Boost​​​官网下载,​​Boost1.61.0​​.
  2. 解压下载文件boost_1_61_0.zipD:/ProgramFiles.
  3. D:\ProgramFiles\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts中启动双击VS2013 x64 兼容工具命令提示快捷方式
  4. 在Windows命令行模式, 切换到D:/ProgramFiles/boost_1_61_0.
D:\ProgramFiles\Microsoft Visual Studio 12.0\VC\bin\x86_amd64>D:
D:\>cd ProgramFiles\boost_1_61_0
D:\ProgramFiles\boost_1_61_0>bootstrap vc12
...
D:\ProgramFiles\boost_1_61_0>.\b2 --address-model=64 -j4
...
...updated 1136 targets...
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
D:\ProgramFiles\boost_1_61_0
The following directory should be added to linker library

三、编译问题


  1. bootstrap fatal error C1034: ctype.h: 不包括路径集
    解决方法:

在系统的环境变量中, 添加 C:\Windows\System32
重启电脑。

四、测试demo

demo1

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

解决方案平台

解决方案配置

demo运行状态

Win32

Debug

pass

Win32

Release

pass

x64

Debug

pass

x64

Release

pass

demo2

#include <boost/lexical_cast.hpp>     
#include <iostream>
using namespace std;
int main()
{
using boost::lexical_cast;
int a = lexical_cast<int>("123");
double b = lexical_cast<double>("123.0123456789");
string s0 = lexical_cast<string>(a);
string s1 = lexical_cast<string>(b);
cout << "number: " << a << " " << b << endl;
cout << "string: " << s0 << " " << s1 << endl;
int c = 0;
try{
c = lexical_cast<int>("abcd");
}
catch (boost::bad_lexical_cast& e){
cout << e.what() << endl;
}
return 0;
}

解决方案平台

解决方案配置

demo运行状态

Win32

Debug

pass

Win32

Release

pass

x64

Debug

pass

x64

Release

pass

demo3

#include <string>
#include <iostream>
#include <boost/regex.hpp>

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

解决方案平台

解决方案配置

demo运行状态

Win32

Debug

fail

Win32

Release

pass

x64

Debug

fail

x64

Release

fail

  • 测试结果
  1. 在C++项目release文件夹中创建jayne.txtjayne.txt中内容如下:
To: George Shmidlap
From: Rita Marlowe

Subject: Will Success Spoil Rock Hunter?
---
  1. Windos命令切换到C++项目release文件内,运行类似以下命令:
example.exe < jayne.txt

输出结果:
​​​Will Success Spoil Rock Hunter?​

参考

[1] ​​vs2013 boost 安装问题若干​​​
[2] ​​​Boost的VS开发环境搭建​​​
[3] ​​​Boost-invocation​