在Visual Studio 2012中进行Googletesting
我正在尝试开始unit testing。 我下载了gtest的最新版本,并将其提取到A:\gtest
作为指定的指示,我打开gtest.sln。 Visual Studio只允许我打开sln,如果我同意更新它。 然后当我尝试build立时,我得到一堆错误:
1>------ Build started: Project: gtest, Configuration: Debug Win32 ------ 1> gtest-all.cc 1>a:\gtest\include\gtest\gtest-printers.h(550): error C2977: 'std::tuple' : too many template arguments 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\gtest-printers.h(558): error C2977: 'std::tuple' : too many template arguments 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C2977: 'std::tuple' : too many template arguments 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1> a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4249) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator9<T1,T2,T3,T4,T5,T6,T7,T8,T9>' being compiled 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4017): error C2955: 'testing::internal::ParamGeneratorInterface' : use of class template requires template argument list 1> a:\gtest\include\gtest\internal\gtest-param-util.h(142) : see declaration of 'testing::internal::ParamGeneratorInterface' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4019): error C2977: 'std::tuple' : too many template arguments 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4030): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4030): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4035): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4035): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1> a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator9<T1,T2,T3,T4,T5,T6,T7,T8,T9>::Iterator' being compiled 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4042): error C2955: 'testing::internal::ParamIteratorInterface' : use of class template requires template argument list 1> a:\gtest\include\gtest\internal\gtest-param-util.h(69) : see declaration of 'testing::internal::ParamIteratorInterface' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4044): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4044): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4077): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4077): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4119): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4119): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4123): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4123): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4204): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4204): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C2977: 'std::tuple' : too many template arguments 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1> a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4505) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>' being compiled 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4256): error C2955: 'testing::internal::ParamGeneratorInterface' : use of class template requires template argument list 1> a:\gtest\include\gtest\internal\gtest-param-util.h(142) : see declaration of 'testing::internal::ParamGeneratorInterface' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4258): error C2977: 'std::tuple' : too many template arguments 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4270): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4270): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4275): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4275): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1> a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282) : see reference to class template instantiation 'testing::internal::CartesianProductGenerator10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>::Iterator' being compiled 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4282): error C2955: 'testing::internal::ParamIteratorInterface' : use of class template requires template argument list 1> a:\gtest\include\gtest\internal\gtest-param-util.h(69) : see declaration of 'testing::internal::ParamIteratorInterface' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4284): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4284): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4320): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4320): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4366): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4366): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4370): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4370): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4456): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4456): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4738): error C2977: 'std::tuple' : too many template arguments 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1> a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4766) : see reference to class template instantiation 'testing::internal::CartesianProductHolder9<Generator1,Generator2,Generator3,Generator4,Generator5,Generator6,Generator7,Generator8,Generator9>' being compiled 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4738): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4738): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4782): error C2977: 'std::tuple' : too many template arguments 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1> a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4813) : see reference to class template instantiation 'testing::internal::CartesianProductHolder10<Generator1,Generator2,Generator3,Generator4,Generator5,Generator6,Generator7,Generator8,Generator9,Generator10>' being compiled 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4782): error C3203: 'tuple' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type 1>a:\gtest\include\gtest\internal\gtest-param-util-generated.h(4782): error C2955: 'std::tuple' : use of class template requires template argument list 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我做错了什么或VS2012这个问题? 我没有附加到谷歌testing,并不反对使用不同的框架,如果它与VS更好的工作,我刚刚听到gtest的很好的东西。
VC ++ 2012不会(也不会)支持可变参数模板; 因此,它的标准库实现尝试使用预处理器生成的重载和专业化来伪造它们。 正如这篇博客文章所指出的,人造variables模板参数的数量默认为5–问题在于gtest正试图用多达10个模板参数实例化std::tuple<>
。
正如博客文章所说,您可以在项目范围内定义_VARIADIC_MAX
macros以支持最多10个参数; 您可能希望通过项目的预处理器定义设置来完成此操作,但重要的是要确保每个TU在包含任何stdlib标头(直接或间接)之前对其进行定义。
我没有使用_VARIADIC_MAX
macros修改VS2012元组实现,而是通过在包括gtest头文件的gtest项目和项目中定义以下两个macros来解决这个问题:
GTEST_HAS_TR1_TUPLE=0 GTEST_USE_OWN_TR1_TUPLE=1
将GTEST_HAS_TR1_TUPLE
设置为0可防止gtest尝试从STL头中使用元组类,并将GTEST_USE_OWN_TR1_TUPLE
设置为1将指示gtest使用自己的元组实现,而不是省略需要元组支持的function。 我个人更喜欢这个选项来调整STL的实现,这个解决scheme应该适用于其他有类似问题的编译器。
这在r675版本中是固定的。 请参阅https://code.google.com/p/googletest/source/detail?r=675
另外,在获得最新版本之前,请将GTEST_USE_OWN_TR1_TUPLE=0
添加到您的预处理器定义中。