Google Test in Visual Studio 2012

C++Visual C++C++11Visual Studio-2012Googletest

C++ Problem Overview


I am trying to get started with unit testing. I downloaded the latest build of gtest, and extracted it to A:\gtest As the instructions specified, I opened gtest.sln. Visual studio only allows me to open the sln if I agree to update it. Then when I try to build I get a pile of errors:

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 ==========

Am I doing something wrong or is this an issue with VS2012? I am not attached to google test and am not opposed to using a different framework if it works better with VS, I had just heard very good things about gtest.

C++ Solutions


Solution 1 - C++

VC++ 2012 does not (and will never) support variadic templates; consequently, its standard library implementation attempts to fake them using preprocessor-generated overloads and specializations. As this blog post notes, the number of faux variadic template parameters defaults to 5 – the problem is that gtest is trying to instantiate std::tuple<> with as many as 10 template arguments.

As the blog post goes on to mention, you can define the _VARIADIC_MAX macro project-wide to support up to 10 parameters; you'll probably want to do this by way of your project's preprocessor definitions setting, but the important thing is to make sure every TU defines it before including any stdlib headers (directly or indirectly).

Solution 2 - C++

Rather than modifying the VS2012 tuple implementation using the _VARIADIC_MAX macro, I solved this problem by defining the following two macros on the gtest projects and projects including gtest headers:

GTEST_HAS_TR1_TUPLE=0
GTEST_USE_OWN_TR1_TUPLE=1

Setting GTEST_HAS_TR1_TUPLE to 0 prevents gtest trying to use the tuple class from the STL headers, and setting GTEST_USE_OWN_TR1_TUPLE to 1 instructs gtest to use its own tuple implementation rather than omitting features that require tuple support. I personally preferred this option to tweaking the STL implementation, and this solution should work on any other compilers that have similar problems.

Solution 3 - C++

Solution 4 - C++

Also, until you get the latest version, add GTEST_USE_OWN_TR1_TUPLE=0 to your pre-processor definitions.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1599559View Question on Stackoverflow
Solution 1 - C++ildjarnView Answer on Stackoverflow
Solution 2 - C++Roger SandersView Answer on Stackoverflow
Solution 3 - C++Corey KosakView Answer on Stackoverflow
Solution 4 - C++Brad WView Answer on Stackoverflow