Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Test in Visual Studio 2012

People also ask

How do I run a Google Test in Visual Studio?

Add a Google Test project in Visual Studio 2022In Solution Explorer, right-click on the solution node and choose Add > New Project. Set Language to C++ and type test in the search box. From the results list, choose Google Test Project. Give the test project a name and choose OK.

How do I use Google Test in Visual Studio 2015?

Add Google Test to the solution: Add a new static library to the solution; call it GTest. In the Visual Studio Solution Explorer, select the GTest project. Add the files gtest_main.cc and gtest-all.cc from C:\googletest\googletest\src as Existing Items.


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).


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.


This is fixed in version r675. See https://code.google.com/p/googletest/source/detail?r=675


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