I'm trying to build googletest with Visual C++ 11, but following code causes an error
我正在尝试使用Visual c++ 11构建google测试,但是遵循代码会导致错误
template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9>
void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>& t, // <-- error C2977
::std::ostream* os) {
PrintTupleTo(t, os);
}
That's an error text:
这是一个错误的文本:
f:\gtest-1.6.0\include\gtest\gtest-printers.h(550): error C2977: 'std::tuple' : too many template arguments
c:\program files (x86)\microsoft visual studio 11.0\vc\include\utility(72) : see declaration of 'std::tuple'
And there is the line 72 of utility
-file:
这是实用文件的第72行:
template<class = _Nil, _MAX_CLASS_LIST>
class tuple; // Line 72
What is the problem with std::tuple
and how to fix it?
std的问题是:tuple和如何修复它?
(BTW: I'm tried unsuccessfully to change std::tr1::tuple
to std::tuple
)
(顺便说一下,我尝试改变std::tr1::tuple::tuple)
7 个解决方案
#1
56
Check out this entry in the msdn blog. VC++11 doesn't have support for variadic templates. They have something they call faux variadics. Scroll down and you will see a paragraph on Faux variadics that talks about tuples. On that paragraph they say the default maximum number of parameters is 5. You can increase it to 10:
请查看msdn博客中的这一条目。vc++ 11不支持变量模板。他们有一种叫人造葡萄树的东西。向下滚动,你会看到一段关于人造杂色的文字,它是关于元组的。在那一段中,他们说默认的最大参数数是5。你可以把它增加到10:
You can define _VARIADIC_MAX project-wide between 5 and 10 inclusive (it defaults to 5). Increasing it will make the compiler consume more memory, and may require you to use the /Zm option to reserve more space for PCHes.
您可以在5到10(默认为5)之间定义_variradic_max项目范围,增加它将使编译器消耗更多的内存,并可能要求您使用/Zm选项为PCHes预留更多的空间。
They say they have a fix incoming to make the default 10 again.
他们说,他们有一个修复进入,使默认10再次。
#2
32
In Visual Studio 2012 (VC11) _VARIADIC_MAX
is by default defined as 5 in header <xstddef>
:
在Visual Studio 2012 (VC11) _variradic_max在header
#if !defined(_VARIADIC_MAX)
#define _VARIADIC_MAX 5
#elif _VARIADIC_MAX < 5 || 10 < _VARIADIC_MAX
#error _VARIADIC_MAX must be between 5 and 10, inclusive
#endif /* !defined(_VARIADIC_MAX) */
if you have multiple VC11 projects include <tuple>
in a solution, it is better to set the macro to all by
如果您有多个VC11项目包括解决方案中的
1) Shift click to select all C++ projects in your solution
1) Shift单击可选择解决方案中的所有c++项目
2) Properties, C/C++, Preprocessor, All Configurations All Platforms, Preprocessor Definitions, <Edit>
2)属性,C/ c++,预处理器,所有平台配置,预处理器定义, <编辑>
3) add before <different options>
a row
3)在 <不同选项> 前添加一行
_VARIADIC_MAX=10;
You can change 10 to any number in 6~10.
你可以在6~10之间把10换成任意数字。
#3
10
Setting GTEST_HAS_TR1_TUPLE
to 0 in gtest.h helped in my case
在gtest中将GTEST_HAS_TR1_TUPLE设置为0。h帮助了我的案子。
Update: of course, the less intrusive way is to define a precompiler flag GTEST_HAS_TR1_TUPLE=0. Check the answers about _VARIADIC_MAX=10
- solves another half of the issue.
更新:当然,不那么烦人的方法是定义一个预编译器标记GTEST_HAS_TR1_TUPLE=0。检查关于_variradic_max =10的答案——解决了问题的另外一半。
#4
2
This is fixed in version r675. See https://code.google.com/p/googletest/source/detail?r=675
这在r675版本中得到了修正。参见https://code.google.com/p/googletest/source/detail?r=675
#5
2
Add below line into your cmake file
在cmake文件中添加以下行
add_definitions(/D_VARIADIC_MAX=10)
#6
2
In Visual Studio 2013, std::tuple
no longer uses _VARIADIC_MAX
and now uses actual variardic template
s, so this problem should be gone.
在Visual Studio 2013中,std:::tuple不再使用_variradic_max,现在使用实际的variardic模板,所以这个问题应该已经解决了。
If you run into it in 2013, it means you are including the wrong standard library.
如果您在2013年遇到它,这意味着您包含了错误的标准库。
#7
1
To use GoogleTest in Visual Studio 2012, you should set _VARIADIC_MAX=10 under Properties->C/C++->Preprocessor->PreprocessorDefinitions on the projects that use it. else you might encounter with below error error C2977: 'std::tuple' : too many template arguments
要在Visual Studio 2012中使用GoogleTest,您应该在属性—>C/ c++ ->预处理器—>预处理器—使用它的项目上设置_variradic_max =10。否则,您可能会遇到下面的错误错误C2977: 'std:::tuple':模板参数太多
#1
56
Check out this entry in the msdn blog. VC++11 doesn't have support for variadic templates. They have something they call faux variadics. Scroll down and you will see a paragraph on Faux variadics that talks about tuples. On that paragraph they say the default maximum number of parameters is 5. You can increase it to 10:
请查看msdn博客中的这一条目。vc++ 11不支持变量模板。他们有一种叫人造葡萄树的东西。向下滚动,你会看到一段关于人造杂色的文字,它是关于元组的。在那一段中,他们说默认的最大参数数是5。你可以把它增加到10:
You can define _VARIADIC_MAX project-wide between 5 and 10 inclusive (it defaults to 5). Increasing it will make the compiler consume more memory, and may require you to use the /Zm option to reserve more space for PCHes.
您可以在5到10(默认为5)之间定义_variradic_max项目范围,增加它将使编译器消耗更多的内存,并可能要求您使用/Zm选项为PCHes预留更多的空间。
They say they have a fix incoming to make the default 10 again.
他们说,他们有一个修复进入,使默认10再次。
#2
32
In Visual Studio 2012 (VC11) _VARIADIC_MAX
is by default defined as 5 in header <xstddef>
:
在Visual Studio 2012 (VC11) _variradic_max在header
#if !defined(_VARIADIC_MAX)
#define _VARIADIC_MAX 5
#elif _VARIADIC_MAX < 5 || 10 < _VARIADIC_MAX
#error _VARIADIC_MAX must be between 5 and 10, inclusive
#endif /* !defined(_VARIADIC_MAX) */
if you have multiple VC11 projects include <tuple>
in a solution, it is better to set the macro to all by
如果您有多个VC11项目包括解决方案中的
1) Shift click to select all C++ projects in your solution
1) Shift单击可选择解决方案中的所有c++项目
2) Properties, C/C++, Preprocessor, All Configurations All Platforms, Preprocessor Definitions, <Edit>
2)属性,C/ c++,预处理器,所有平台配置,预处理器定义, <编辑>
3) add before <different options>
a row
3)在 <不同选项> 前添加一行
_VARIADIC_MAX=10;
You can change 10 to any number in 6~10.
你可以在6~10之间把10换成任意数字。
#3
10
Setting GTEST_HAS_TR1_TUPLE
to 0 in gtest.h helped in my case
在gtest中将GTEST_HAS_TR1_TUPLE设置为0。h帮助了我的案子。
Update: of course, the less intrusive way is to define a precompiler flag GTEST_HAS_TR1_TUPLE=0. Check the answers about _VARIADIC_MAX=10
- solves another half of the issue.
更新:当然,不那么烦人的方法是定义一个预编译器标记GTEST_HAS_TR1_TUPLE=0。检查关于_variradic_max =10的答案——解决了问题的另外一半。
#4
2
This is fixed in version r675. See https://code.google.com/p/googletest/source/detail?r=675
这在r675版本中得到了修正。参见https://code.google.com/p/googletest/source/detail?r=675
#5
2
Add below line into your cmake file
在cmake文件中添加以下行
add_definitions(/D_VARIADIC_MAX=10)
#6
2
In Visual Studio 2013, std::tuple
no longer uses _VARIADIC_MAX
and now uses actual variardic template
s, so this problem should be gone.
在Visual Studio 2013中,std:::tuple不再使用_variradic_max,现在使用实际的variardic模板,所以这个问题应该已经解决了。
If you run into it in 2013, it means you are including the wrong standard library.
如果您在2013年遇到它,这意味着您包含了错误的标准库。
#7
1
To use GoogleTest in Visual Studio 2012, you should set _VARIADIC_MAX=10 under Properties->C/C++->Preprocessor->PreprocessorDefinitions on the projects that use it. else you might encounter with below error error C2977: 'std::tuple' : too many template arguments
要在Visual Studio 2012中使用GoogleTest,您应该在属性—>C/ c++ ->预处理器—>预处理器—使用它的项目上设置_variradic_max =10。否则,您可能会遇到下面的错误错误C2977: 'std:::tuple':模板参数太多