一、准备工作

1、下载最新版本的boost库.所在地址:boost_1_53_0.zip.官方推荐7z压缩格式的,因为其压缩效率更好,相应包的大小也比较小。

2、解压缩到指定目录,如C:\boost_1_53.下面开始遵照官方页面的步骤进行编译。()

  1. 进入目录tools\build\v2\
  2. 运行bootstrap.bat脚本文件
  3. 运行命令:b2 install --prefix=PREFIX。其中PREFIX是为Boost.Build指定的安装目录,生成的编译工具将会存放在该目录下。我指定为c:\boost_1_53
  4. 把PREFIX/bin路径加入到系统的环境变量。这时要重启一下命令提示符,以便于应用新的环境变量。

3、下面要选择一个编译平台。所谓的编译平台,指的具体的编译环境,官方给出了一个列表。

这里,我们的编译环境使用的是VS2010,也就是VC10,所以我们将toolset指定为msvc.在VS2010的工具选项中打开visual studio命令提示(2010) 。这个命令提示框中已经配置了VS2010的编译环境变量,不用再手动配置什么环境变量。

4、接下来还有一个准备工作要做,为编译期间产生的中间文件指定一个目录,我指定为c:\boost_1_53\build_manual。

二、源码编译

5、开始编译。退回到boost源码的根目录,运行命令:

   b2 --build-dir=build-directory toolset=toolset-name --build-type=complete stage
  • 上述命令中下划线的选项必须是小写的。因为b2是大小写敏感的。(b2是boost build工具的缩写)
  • build-directory是第4步中指定的中间文件目录,toolset是上述表格中的随意一个,complete指示编译工具编译所有库文件版本(如static, runtime, dll, single thread, multi-thread)。
  • stage的含义:该选项指示编译工具将编译完成的所有lib文件都存放在stage\lib\下面。如果要更改,使用b2的选项:--stagedir=directory。
我的编译命令为: b2 --build-dir=c:\boost_1_53\build_manual toolset=msvc --build-type=complete stage

6、全部编译时间耗费了半个小时(机器性能较好的缘故)。一般要耗费将近一小时。编译过程会产生很多警告,这些都不要紧。只要不产生errors而终止编译过程,那么都是没有关系的。

编译产生的文件会有四五个GB大小。所以,最好保证源代码所在文件有足够的磁盘空间。

7、编译完成后,只有stage\lib\下面这些个文件lib文件,才是我们最终需要的。其他编译产生的文件都无关痛痒。

8、配置VS2010开发boost程序的环境。

  • 在VS2010中,工具>>选项>>项目和解决方案>>VC++目录这个功能已经被取消了,没办法看到全局的VC++目录设置。所以,我们只好在项目的属性中设置。这样稍显麻烦。每一个boost工程都要重新配置一次,无法达到一劳永逸的效果。
  • 打开项目属性页面,点击"C/C++"和"链接器"这两个结点,具体配置如下所示:

9、注意自己配置的地方:附加包含目录附加库目录。要注意的是,附加包含目录中,一定不要写成这种形式:E:\codes\src\boost_1_53_0\boost!!这样,在包含头文件的时候,编译器会报错找不到头文件。因为写成这样,会把\boost这个路径给去掉了。而头文件内部依赖的很多其他头文件又是相对于\boost这个路径的。编译无疑无法通过。

三、测试结果

10、编译boost库自带的一个源程序:

 1 #include <iostream>
2 #include <fstream>
3 #include <ctime> // std::time
4
5 #include <boost/random/linear_congruential.hpp>
6 #include <boost/random/uniform_int.hpp>
7 #include <boost/random/uniform_real.hpp>
8 #include <boost/random/variate_generator.hpp>
9 #include <boost/generator_iterator.hpp>
10
11 // This is a typedef for a random number generator.
12 // Try boost::mt19937 or boost::ecuyer1988 instead of boost::minstd_rand
13 typedef boost::minstd_rand base_generator_type;
14
15 // This is a reproducible simulation experiment. See main().
16 void experiment(base_generator_type & generator)
17 {
18 // Define a uniform random number distribution of integer values between
19 // 1 and 6 inclusive.
20 typedef boost::uniform_int<> distribution_type;
21 typedef boost::variate_generator<base_generator_type&, distribution_type> gen_type;
22 gen_type die_gen(generator, distribution_type(1, 6));
23
24 // If you want to use an STL iterator interface, use iterator_adaptors.hpp.
25 boost::generator_iterator<gen_type> die(&die_gen);
26 for(int i = 0; i < 10; i++)
27 std::cout << *die++ << " ";
28 std::cout << '\n';
29 }
30
31 int main()
32 {
33 // Define a random number generator and initialize it with a reproducible
34 // seed.
35 base_generator_type generator(42);
36
37 std::cout << "10 samples of a uniform distribution in [0..1):\n";
38
39 // Define a uniform random number distribution which produces "double"
40 // values between 0 and 1 (0 inclusive, 1 exclusive).
41 boost::uniform_real<> uni_dist(0,1);
42 boost::variate_generator<base_generator_type&, boost::uniform_real<> > uni(generator, uni_dist);
43
44 std::cout.setf(std::ios::fixed);
45 // You can now retrieve random numbers from that distribution by means
46 // of a STL Generator interface, i.e. calling the generator as a zero-
47 // argument function.
48 for(int i = 0; i < 10; i++)
49 std::cout << uni() << '\n';
50
51 /*
52 * Change seed to something else.
53 *
54 * Caveat: std::time(0) is not a very good truly-random seed. When
55 * called in rapid succession, it could return the same values, and
56 * thus the same random number sequences could ensue. If not the same
57 * values are returned, the values differ only slightly in the
58 * lowest bits. A linear congruential generator with a small factor
59 * wrapped in a uniform_smallint (see experiment) will produce the same
60 * values for the first few iterations. This is because uniform_smallint
61 * takes only the highest bits of the generator, and the generator itself
62 * needs a few iterations to spread the initial entropy from the lowest bits
63 * to the whole state.
64 */
65 generator.seed(static_cast<unsigned int>(std::time(0)));
66
67 std::cout << "\nexperiment: roll a die 10 times:\n";
68
69 // You can save a generator's state by copy construction.
70 base_generator_type saved_generator = generator;
71
72 // When calling other functions which take a generator or distribution
73 // as a parameter, make sure to always call by reference (or pointer).
74 // Calling by value invokes the copy constructor, which means that the
75 // sequence of random numbers at the caller is disconnected from the
76 // sequence at the callee.
77 experiment(generator);
78
79 std::cout << "redo the experiment to verify it:\n";
80 experiment(saved_generator);
81
82 // After that, both generators are equivalent
83 assert(generator == saved_generator);
84
85 // as a degenerate case, you can set min = max for uniform_int
86 boost::uniform_int<> degen_dist(4,4);
87 boost::variate_generator<base_generator_type&, boost::uniform_int<> > deg(generator, degen_dist);
88 std::cout << deg() << " " << deg() << " " << deg() << std::endl;
89
90 {
91 // You can save the generator state for future use. You can read the
92 // state back in at any later time using operator>>.
93 std::ofstream file("rng.saved", std::ofstream::trunc);
94 file << generator;
95 }
96
97 getchar();
98 return 0;
99 }

这是一个生成随机数的程序,其运行结果如下:

http://www.cnblogs.com/csuftzzk/archive/2013/04/30/3052046.html

VS2010下编译配置Boost_1.53的更多相关文章

  1. CxImage在VS2010下的配置

    http://blog.csdn.net/youzhuo/article/details/24601621 一.编译Cximage 1.在SourceForge上下载cximage702_full.7 ...

  2. VS2010 下编译 cocos2d-x-2.1.4

    在VS2010 下编译 cocos2d-x-2.1.4   首先感谢 cocos2d-x 团队为我们做出这么好的跨平台框架,让我们这些码农省了很多时间,事半功倍. 里沃特最近在编译 win32 版本的 ...

  3. 在vs2010下编译boost

    1. 解压缩后,运行bootstrap.bat批处理文件,得到bjam.exe; 2. 在vs2010下编译boost boost最新版本已经支持vs2010,然而直接下载编译会发现一堆bug: 首先 ...

  4. 在VS2010下编译和使用tesseract_ocr识别验证码

    对于自动识别验证码,使用trsseract是个不错的选择,有兴趣的的朋友可以试试. 编译tesseract 官网提供了vs2008的编译说明和工程,但在vs2010下的编译时基本相同的,因此我使用的方 ...

  5. windows下编译配置libnet-1.2-rc3

    1.下载winpcap(一个底层驱动,可以嗅探.过滤网卡数据包,发包).exe安装包,傻瓜一步式安装 2.下载WpdPack_4_1_2,这个是winpcap的开发者包,解压之后只需要配置相关路径. ...

  6. OpenCV2.3.1在Win7+VS2010下的配置过程(转)

    转自:http://blog.csdn.net/mygis2005/article/details/10472717 这篇博客很好的解决了我遇到的问题,所以转到自己的博客里,方便以后进行查阅. 1.  ...

  7. 转:在VS2010下编译、调试和生成mex文件

    最近帮人调了一个程序,是网上公开的代码,利用matlab与c++混合编程做三维模型关键点检测,发现他们可以用VS2010编译.调试.生成mexw32文件,因此觉得之前在Matlab上利用mex命令真是 ...

  8. vs2010下编译osip2和eXosip2的4.0.0版的静态库及搭建开发环境

    转载于:http://blog.csdn.net/lbc2100/article/details/48293911 本文为参考网上的动态库的方式,进行静态库的实现,在此对动态库的作者表示感谢. 第一步 ...

  9. OpenCV2.3.1在Win7+VS2010下的配置过程

    1.  假定电脑上已经安装了VS2010程序,若没有,首先安装vs2010.下载OpenCV2.3.1,网址:http://sourceforge.net/projects/opencvlibrary ...

随机推荐

  1. maven 依赖(依赖范围,聚合,继承等)

    目录: 1.什么是依赖? 2.依赖的管理:依赖的范围与传递,依赖的排除,依赖的原则(maven对依赖冲突的处理原则) 3.依赖的版本管理 4.继承与聚合 1.什么是依赖? 简单的讲,当jar包A需要j ...

  2. mac下装php5.6

    OS X10.11自带了php5.5,项目中使用的是php5.6,用brew install --without-apache --with-fpm --with-mysql php56装php5.6 ...

  3. CSS拾遗(一)

    重新看<精通CSS(第二版)>做一些记录,方便今后巩固. 1.外边距叠加 只有普通文档流中块框的垂直外边距才会发生外边距叠加.行内框.浮动框.或绝对定位框之间的外边距不会叠加. 2.相对定 ...

  4. Myeclipse 6.5 增加对 JavaEE 6 的支持

    网上找了一会没发现什么好的方法一想干脆自己动手丰衣足食,搜索MYECLIPSE_JAVAEE_5_CONTAINER找到了 MyEclipse6.5\myeclipse\eclipse\plugins ...

  5. 解决mysql连接异常—-com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception

    DBCP连接池连接MySql数据库时,一奇葩数据库设置为30秒内无请求自动断开.超时后链接无法关闭,活动链接数飞奔,最后挂掉. 网上找了一圈,一般是这三种,方法一pass,方法二测试无效可能设置错了吧 ...

  6. git命令评测

    近日得知git命令在库进行操作,查找git尽管小命令(当然,也不能太小),但他们是一个非常强大的组合,更重要的是,它是非常的效果不同状态的命令是不一样的打.该博文总结git命令.. Git命令 命令小 ...

  7. python 判断一个数为?

    1. 判断一个变量是否数字(整数.浮点数)? instance('a', (int, long, float)) True isinstance('a', (int, long, float)) Fa ...

  8. 特征价格(Hedonic price)

    特征价格法,又称 Hedonic 模型法和效用估价法,认为房地产由众多不同的特征组成,而房地产价格是由所有特征带给人们的效用决定的.由于各特征的数量及组合方式不同,使得房地产的价格产生差异.因此,如能 ...

  9. Scala(一) 环境搭建和HelloWorld

    环境 scala 1.12.2 JDK 1.8.0_131 Win10 Eclipse 4.6.1   软件下载   官网:http://www.scala-lang.org/ 点击DOWNLOAD进 ...

  10. Hibernate4与hibernate3有错误的版本号的主要区别所造成的不一致

    Hibernate版本号修改 Hibernate4的修改较大仅仅有spring3.1以上版本号可以支持,Spring3.1取消了HibernateTemplate,由于Hibernate4的事务管理已 ...