D:\VS2017\down\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64
1.测试环境变量 cl
没有,就找到vs2017下面的 如上目录,加入到环境变量中
可以在cmd中用 echo %path% 查看,是否加入成功
2. 开始编译
用管理员模式,打开x64 Native Tools(2017开发人员命令)
到C:\Program Files (x86)\boost\boost_1_64_0
输入: bootstrap.bat
会生产文件: b2.exe bjam.exe project-config.jam
3. 用记事本打开 当前目录下的 project-config.jam
修改成如下:
import option ;
using msvc : 14.0 : "D:\VS2017\down\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64";
option.set keep-going : false ;
4. 在D:\boost\boost_1_64_0目录下,新建build目录,可以把中间生产文件放在其中
5. 在命令行,输入如下指令:
b2.exe stage --toolset=msvc-14.0 address-model=64 --stagedir="D:\boost\boost_1_64_0" threading=multi --build-type=complete --build-dir="D:\boost\boost_1_64_0\build"
具体介绍:
--toolset:设置编译器,如果用VC,设msvc, 用MinGW就设gcc。
stage:可选install,选stage只生成库(静态库和动态库),install还包含include目录,其实,可以直接用我们下载下来的BOOST包里的boost目录,这个目录和install生成的include目录内容基本一样。所以也就不用了。
--build-dir=”[temporary folder name”:编译的临时文件存放位置。
--stagedir=” stage folder name]”:存放编译后库文件的路径,默认是stage。
--build-type=complete:编译所有版本
{
variant=debug|release 决定编译什么版本(Debug or Release?)
link=static|shared 决定使用静态库还是动态库。
threading=single|multi 决定使用单线程还是多线程库。
runtime-link=static|shared 决定是静态还是动态链接C/C++标准库。
}
link:是动态库还是静态库,static | shared,一般默认静态。
address-mode:address-model=64,如果没有这个属性的话,会默认生成32位的平台库,加入这个选项才能生成64位的DLL。如果运行在VS32位的命令行下需要添加” architecture=x86”,笔者使用x64 Native Tools Command Prompt for VS 2017没有x86与x64之间的矛盾,所以未设置。
6.编译完成之后结束。
7. 调试
在项目属性中,C/C++ 常规中,加入外部头文件路径
在连接器 常规中 加入库的目录
如果产生打不开文件问题。。
解决:点击调试-----选项-----右边勾上“启用源服务器支持”----左边点“符号”—右边勾选“微软符号服务器”。
测试代码如下:
// boostdemo.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <boost/lexical_cast.hpp>
using namespace std;
int main()
{
using boost::lexical_cast;
int a = lexical_cast<int>("123");
double b = lexical_cast<double>("12.90");
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;
}
system("pause");
return 0;
}