编译boost date_time

来源:互联网 发布:帝国时代 知乎 编辑:程序博客网 时间:2024/05/17 23:12

boost当前最新版本:1.47.0


分别在vs2005和bcb 6下编译.

.vs2005下可用

.bcb 6编译出错


1.下载:

下载位置:www.boost.org

文件名:boost_1_47_0.zip

解压下载的文件:以下用$BOOST_HOME表示解压的主目录

 

2.生成bjam.exe文件,该文件是用来编译boost的程序

.cd $BOOST_HOME

.booststrap.bat

在当前目录下生成bjam.exe(还有b2.exe)

 

3.编译

.cd $BOOST_HOME\libs\date_time\build

3.1 vs2005编译

..\..\..\bjam toolset=msvc--build-dir=e:\boost_build_vc

生成的lib/dll位于目录e:\boost_build_vc\boost\bin.v2\libs\date_time\build\msvc-8.0\debug\threading-multi下。

 

3.2 Borland C++(version:5.6.4)编译

..\..\..\bjam toolset=borland--build-dir=e:\boost_build_bcb

 

报编译错误:

Error E2034..\..\..\boost/type_traits/add_rvalue_reference.hpp 56: Cannot convert'is_void<T>::value' to 'bool'

 

对应的代码位置(boost\type_traits\add_rvalue_reference.hpp):

   template <typename T>

   struct add_rvalue_reference_imp

    {

      typedef typename boost::type_traits_detail::add_rvalue_reference_helper

                  <T,(!is_void<T>::value && !is_reference<T>::value) >::typetype; ///< 此行错误

   };

 

可能是由于编译器不支持,见以下链接的相关说明:

http://www.boost.org/doc/libs/1_31_0/more/int_const_guidelines.htm

Don't use logical operators in integral constant expressions; use template meta-programming instead.

 

The header <boost/type_traits/ice.hpp> contains a number of workaround templates, that fulfil the role of logical operators, for example instead of:

 

INTEGRAL_CONSTANT1 || INTEGRAL_CONSTANT2

 

Use:

 

::boost::type_traits::ice_or<INTEGRAL_CONSTANT1,INTEGRAL_CONSTANT2>::value


4.资源:

(1)http://www.boost.org

boost的官方站点

 

(2)http://bcbboost.sourceforge.net

提供boost对bcb各个版本支持的测试结果和补丁.

从测试报告看,boost的许多库都不支持bcb.新版本的测试已不对bcb 5.6.4进行了.


5.测试代码

针对bcb 5.6.4下出现的问题,验证诊断的原因:add_rvalue_reference_imp不符合关于以下在模板中使用常量表达式的规范:

Don't use logical operators in integralconstant expressions; use template meta-programming instead.

 

用测试代码在bcb 6环境下测试:

#include "boost/type_traits/is_void.hpp"

using namespace boost;

template <typename T,int>

        struct test_template_1 {

        T value;

    };

 template <typename T>

  struct test_template_2

    {

//   typedef typename test_template_1<T, !(int)is_void<T>::value&&is_void<T>::value > type; ///< 仿add_rvalue_reference_imp

 

///< 以下是测试的3种情况:

          typedef typename test_template_1<T, (bool)1&&1 > type;      ///< ok

     typedef typename test_template_1<T, is_void<T>::value&&1 > type;  /// error

     typedef typename test_template_1<T, is_void<T>::value+1 > type;  /// ok

};

 

 

可以认为是bcb编译器的原因.并且从add_rvalue_reference_imp的代码结构看,似乎也没有合适的宏能够帮助解决此问题.

初步结论:如果要在bcb上使用boost date_time,则需要升级bcb.

 



原创粉丝点击