VS2012 下编译boost1.52
2012-12-25 20:35 Scott Guthrie Liu 阅读(1796) 评论(1) 编辑 收藏 举报1. 下载boost_1_52_0.7z
http://sourceforge.net/projects/boost/files/boost/1.52.0/
2. 解压缩到d:\boost目录下
3. 编译bjam
(1)从开始菜单运行“VS2012 开发人员命令提示”
(2)cd到D:\boost\boost_1_52_0下执行bootstrap.bat,然后,会在D:\boost\boost_1_52_0下生成bjam.exe
4.设定编译环境
我的机器上仅安装了VS2012所以未配置
5. 编译boost库
本人使用的bjam命令如下:
bjam stage --toolset=msvc-11.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-python --without-serialization --without-wave --stagedir="D:\boost\boost_1_52_0\bin\vc11" link=static runtime-link=shared runtime-link=static threading=multi debug release
15分钟编译完毕。
关于编译的取舍参考 :http://www.boost.org/doc/libs/1_52_0/more/getting_started/windows.html
The only Boost libraries that must be built separately are:
- 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
A few libraries have optional separately-compiled binaries:
- 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.Math has binary components for the TR1 and C99 cmath functions.
- Boost.Random has a binary component which is only needed if you're using random_device.
- Boost.Test can be used in “header-only” or “separately compiled” mode, although separate compilation is recommended for serious use.
6.设定vs2012环境
用VS 2012新建一个win32控制台应用程序名为Hello。
“属性管理” -> Microsoft.Cpp.Win32.user -> 右键“属性”
在弹出的对话框"C++目录" -> “包含目录”添加 D:\boost\boost_1_52_0
-> “库目录”添加 D:\boost\boost_1_52_0\bin\vc11\lib
通过使用 boost/regex.hpp 简单程序判断配置正确。
#include <boost/timer.hpp> #include <cassert> #include "boost/regex.hpp" using namespace boost; int _tmain(int argc, _TCHAR* argv[]) { cout << "Hello , World !" << endl; timer t; cout << "elapsed_max " << t.elapsed_max() / 3600 << "h" <<endl; cout<< "elapsed_min " << t.elapsed_min() << "s" << endl; cout << "elapsed " << t.elapsed() << "s" <<endl; // 3 digits, a word, any character, 2 digits or "N/A", // a space, then the first word again boost::regex reg("\\d{3}([a-zA-Z]+).(\\d{2}|N/A)\\s\\1"); std::string correct="123Hello N/A Hello"; std::string incorrect="123Hello 12 hello"; assert(boost::regex_match(correct,reg)==true); assert(boost::regex_match(incorrect,reg)==false); return 0; }
主要参考 :
http://www.cnblogs.com/wondering/archive/2009/05/21/boost_setup.html
http://www.cppblog.com/flyinghare/archive/2010/09/07/126078.aspx
http://chenrongya.blog.163.com/blog/static/874741962010102041157963/