【问题标题】:Errors when compiling catch with Visual Studio 2008使用 Visual Studio 2008 编译 catch 时出错
【发布时间】:2017-09-28 20:22:16
【问题描述】:

更新:使用 catch 1.9.7 解决了这个问题。

我刚刚开始使用 catch,甚至无法编译一个简单的测试项目。我正在使用 Visual Studio 2008 并拥有 catch.hpp v1.10.0(单文件版本)。

我按照 catch 教程创建了一个简单的测试项目。 main.cpp 是唯一的文件,代码包括:

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

TEST_CASE("test case 1")
{
    REQUIRE(1==2);
}

编译时出现以下错误:

c:\utilities\catch\catchtest\catchtest\catch.hpp(1333) : warning C4181: qualifier applied to reference type; ignored
c:\utilities\catch\catchtest\catchtest\catch.hpp(1838) : see reference to class template instantiation 'Catch::Internal::Evaluator<T1,T2,Op>' being compiled
with
[
    T1=const int &,
    T2=const int &,
    Op=IsEqualTo
]
c:\utilities\catch\catchtest\catchtest\catch.hpp(1836) : while compiling class template member function 'void Catch::BinaryExpression<LhsT,Op,RhsT>::endExpression(void) const'
with
[
    LhsT=const int &,
    Op=IsEqualTo,
    RhsT=const int &
]
c:\utilities\catch\catchtest\catchtest\main.cpp(8) : see reference to class template instantiation 'Catch::BinaryExpression<LhsT,Op,RhsT>' being compiled
with
[
    LhsT=const int &,
    Op=IsEqualTo,
    RhsT=const int &
]
c:\utilities\catch\catchtest\catchtest\catch.hpp(1333) : error C2529: 'lhs' : reference to reference is illegal
c:\utilities\catch\catchtest\catchtest\catch.hpp(1333) : warning C4181: qualifier applied to reference type; ignored
c:\utilities\catch\catchtest\catchtest\catch.hpp(1333) : error C2529: 'rhs' : reference to reference is illegal
c:\utilities\catch\catchtest\catchtest\catch.hpp(1838) : error C2664: 'Catch::Internal::Evaluator<T1,T2,Op>::evaluate' : cannot convert parameter 1 from 'const int' to 'const int &(&)'
with
[
    T1=const int &,
    T2=const int &,
    Op=IsEqualTo
]
c:\utilities\catch\catchtest\catchtest\catch.hpp(1839) : error C2228: left of '.endExpression' must have class/struct/union

任何帮助将不胜感激。我无法在 catch 文档或在线找到任何内容,我渴望开始使用它。

【问题讨论】:

    标签: c++ visual-studio-2008 catch-unit-test


    【解决方案1】:

    最新的 Catch 大师适用于现代 C++ 编译器,而 Visual Studio 2008 编译器现在已经很老了。您可以使用一些开关来降级某些功能:

    https://github.com/philsquared/Catch/blob/master/docs/configuration.md

    尝试在#include'ing catch 之前定义“CATCH_CONFIG_NO_CPP11”。

    【讨论】:

      【解决方案2】:

      供将来参考:this commit 破坏了对 MSVC 9 的支持并恢复 b6e7c9bd7a160c07c5de894292022687895c17a3(在此基础上完成),然后这个就足以解决问题。

      【讨论】:

        猜你喜欢
        • 2012-09-24
        • 1970-01-01
        • 2013-05-20
        • 1970-01-01
        • 1970-01-01
        • 2011-04-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多