2014-03-17

Compile Error when we build the GoogleTest in VS2012

我嘗試要在VS2012上試試Unit Test

Step 1 :
去googletest 網站download googletest project
https://code.google.com/p/googletest/

目前版號是gtest-1.7.0

Step 2:
解壓縮zip

Step 3 :
用VS2012 開啟專案
.\gtest-1.7.0\msvc\

Step 4 :
Rebuild projects

根據Primer上的說明 欲先玩googletest 必先compile之
To write a test program using Google Test, you need to compile Google Test into a library and link your test with it. 

但是正常情況下會compile error
錯誤原因為 :
Error 5 error C2977: 'std::tuple' : too many template arguments d:\coding\gtest-1.7.0\include\gtest\gtest-printers.h

[Root Cause]
http://stackoverflow.com/questions/12558327/google-test-in-visual-studio-2012
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 through 10 parameters; you'll probably want to do this by way of your project's preprocessor definitions setting.

[Solution]
打開4個Project的Property
properties -> C\C++ Preprocessor -> Processor Definitions -> <edit...>

Add "_VARIADIC_MAX=10"
Save and Rebuild all projects





0 意見: