编译,测试BOOST

来源:互联网 发布:数据库查询语句大全 编辑:程序博客网 时间:2024/05/29 10:27


在使用vs2013编译boost-1.55.0之前,先要给boost做下修改:

boost_1_55_0\boost\intrusive\detail\has_member_function_callable_with.hpp line:222

[cpp] view plaincopyprint?
  1. template<class U>  
  2. static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)  
  3.        <U> Test(BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U>*);  
替换成以下内容:

[cpp] view plaincopyprint?
  1. #ifdef BOOST_MSVC  
  2.      template<class U>  
  3.      static decltype(boost::move_detail::declval<Fun>().BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME()  
  4.            , boost_intrusive_has_member_function_callable_with::yes_type())  
  5.            Test(Fun*);  
  6. #else  
  7.      template<class U>  
  8.      static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)  
  9.            <U> Test(BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U>*);  
  10. #endif  

1、管理员权限cmd中运行:

      "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"编译32位

      "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\vcvars64.bat"编译64位

2、命令行进入boost所在目录,运行bootstrap.bat(我的64位没有执行步骤一出错)

3、32位编译:

      主意要把换行符去掉:把命令复制到记事本去掉换行符

[cpp] view plaincopyprint?
  1. bjam.exe stage --toolset=msvc-12.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-serialization   
  2. --without-wave --without-test --without-program_options --without-serialization --without-signals --stagedir=".\bin\vc12_x86" link=static   
  3. runtime-link=shared threading=multi debug release  

     64位编译:

[plain] view plaincopyprint?
  1. bjam.exe stage --toolset=msvc-12.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-serialization   
  2. --without-wave --without-test --without-program_options --without-serialization --without-signals --stagedir=".\bin\vc12_x64" link=static   
  3. runtime-link=shared threading=multi debug release address-model=64    
4、添加boostest工程的包含目录和库目录

包含目录添加  D:\boost_1_55_0

库目录添加    D:\boost_1_55_0\stage\lib

具体如下图:




5、测试代码:

[cpp] view plaincopyprint?
  1. #include <boost/lexical_cast.hpp>       
  2.   
  3. #include <iostream>       
  4.   
  5. using namespace std;  
  6.   
  7. int main()  
  8.   
  9. {  
  10.   
  11.     using boost::lexical_cast;  
  12.   
  13.     int a = lexical_cast<int>("123");  
  14.   
  15.     double b = lexical_cast<double>("123.0123456789");  
  16.   
  17.     string s0 = lexical_cast<string>(a);  
  18.   
  19.     string s1 = lexical_cast<string>(b);  
  20.   
  21.     cout << "number: " << a << "  " << b << endl;  
  22.   
  23.     cout << "string: " << s0 << "  " << s1 << endl;  
  24.   
  25.     int c = 0;  
  26.   
  27.     try{  
  28.   
  29.         c = lexical_cast<int>("abcd");  
  30.   
  31.     }  
  32.   
  33.     catch (boost::bad_lexical_cast& e){  
  34.   
  35.         cout << e.what() << endl;  
  36.   
  37.     }  
  38.     system("pause");  
  39.     return 0;  
  40.   
  41. }  
结果:


 

0 0