vs 下安装boost

  • 首先到boost官网去下载最新的版本的boost库,选对对应的平台版本。

    下载官网



  • 等待程序编译完成,大约要两个小时左右,会在boost根目录下生成bin.v2和stage两个文件夹,其中bin.v2是生成的中间文件,大小在2.7G左右,可以直接删除。

bjam生成后观察下,我先是按照 编译静态库的选项编译的,命令如下,

bjam install stage --toolset=msvc-12.0 --stagedir="C:\Boost" link=static runtime-link=static threading=multi debug release

的方式生成的只有include 和 lib 目录,关键字,static,multi,debug,release,于是,lib里面只有60多项,名字都是
libboost_thread-vc120-mt-gd-1_61.lib,libboost_thread-vc120-mt-1_61.lib 之类的成对出现。不难猜出,都是multi多线程,一个debug,一个
release版本。且都是静态的lib库。
-- 可见,不同的编译参数,生成的东西会有所区别。如果只需要部分boost,可以指定bjam的参数。懒人还是完全编译的好。


  • 打开vs,boost是通用库,我可不想每个工程都要到属性里配置目录。下面这样即可配置全局的环境。

视图->其它窗口->属性管理器->当前项目->Debug|Win32->Microsoft.Cpp.Win32.user双击

在弹出的属性对话框中:

通用属性->VC++目录:"包含目录": boost的根目录,例:D:\boost_1_58_0

"库目录": stage下的链接库目录,例:D:\boost_1_58_0\stage\lib

  • 其它错误 (我真衰,照的别人的做都能错误百出)
    1. 电脑有不止一个vc版本,需要 --toolset=msvc-12.0 指定vc版本,默认是高版本的vc.
    2. 报错 “编译器内部错误”,坑爹,微软也会时不时的软一下,我的vs2013没有打补丁更新,装上update 5就不软了。
  • 测试代码如下,网上抄的,但是很有可能只有一个测试代码成功,另一个就报 找不到文件,链接不到,无法解析 等错误。

测试代码(1)

#include "stdafx.h"
#include <iostream>  
#include <boost/thread/thread.hpp>  
void hello()
{
std::cout << "Hello world, I'm a thread!" << std::endl;
}
int main()
{
boost::thread thrd(&hello);
thrd.join();
}

测试代码(2)

	#include <cstdlib>  
	
	#include <iostream>  
	#include <vector>  
	#include <iterator>  
	#include <algorithm>  
	
	#include <boost/timer.hpp>  
	#include <boost/progress.hpp>  
	
	#include <libs/date_time/src/gregorian/greg_names.hpp>  
	#include <libs/date_time/src/gregorian/date_generators.cpp>  
	#include <libs/date_time/src/gregorian/greg_month.cpp>  
	#include <libs/date_time/src/gregorian/gregorian_types.cpp>  
	
	#include <boost/date_time/posix_time/posix_time.hpp>  
	
	using namespace boost;  
	
	int main()  
	{  
	boost::timer t;  
	
	boost::progress_display pd(100);  
	
	for (int i = 0; i < 100; ++i) //进度条  
	{  
	++pd;  
	}  
	
	boost::gregorian::date dt(2009, 12, 8); //date_time 库  
	assert(dt.year() == 2009);  
	assert(dt.day() == 8);  
	boost::gregorian::date::ymd_type ymd = dt.year_month_day();  
	std::cout<<"\n"<<ymd.year<<"/"<<ymd.month<<"/"<<ymd.day<<" the day is "  
	<<dt.day_of_year() <<" days of this year"<< std::endl;  
	
	std::cout << boost::gregorian::to_iso_extended_string(dt) << std::endl; //转换为其他格式  
	std::cout << boost::gregorian::to_iso_string(dt) << std::endl;  
	std::cout << boost::gregorian::to_simple_string(dt) << std::endl<<std::endl;  
	
	//对数组排序操作  
	std::vector<int> test_vc(100);  
	std::vector<int>::iterator beg_it = test_vc.begin();  
	std::vector<int>::iterator end_it = test_vc.end();  
	std::srand(std::time(NULL));  
	
	std::for_each(beg_it, end_it, [](int& n){n = rand(); });  
	std::copy(beg_it, end_it, std::ostream_iterator<int>(std::cout, " "));  
	std::cout << std::endl << std::endl;  
	std::sort(beg_it, end_it, std::greater<int>());  
	std::copy(beg_it, end_it, std::ostream_iterator<int>(std::cout, " "));  
	std::cout << std::endl<<std::endl;  
	
	boost::posix_time::ptime pt(boost::gregorian::date(2005, 2, 6));  
	
	std::cout << t.elapsed() << "s" << std::endl; //程序运行时间  
	
	system("pause");  
	
	return 0;  
	}

posted on 2016-06-27 04:57  ShawSpring  阅读(414)  评论(0编辑  收藏  举报

导航