Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::tr1 with visual studio 2017

I have some C++ code that uses some version of Google's GTest framework. This code used to compile fine with Visual Studio 2015. I just upgraded to VS2017, and now I get a bunch of errors like this:

error C2039: 'tr1': is not a member of 'std'
error C3083: 'tr1': the symbol to the left of a '::' must be a type

Is some compiler option needed to use std::tr1 in VS2017?

like image 970
Dess Avatar asked Mar 17 '17 00:03

Dess


2 Answers

One option is to re-enable TR1; do this by defining the macro _HAS_TR1_NAMESPACE, as briefly mentioned in this blog article. If you're using an MSBuild project then this is best done by way of your project's Preprocessor Definitions setting; or if you're using a precompiled header, by defining it at the top of said PCH.

A better option is to inform GTest that your compiler supports C++11 by defining the macro GTEST_LANG_CXX11 to 1 before including any GTest headers; then it will use std::tuple rather than std::tr1::tuple*. (GTest's C++11-detection logic is __cplusplus-oriented, which VC++ has not yet updated despite being mostly C++11 and C++14 compliant. I would say this is a bug in GTest since it supports VC++ elsewhere throughout the configuration logic.)

* Not to mention the other C++11 features, which is why this is by far the better option ;-]

like image 118
ildjarn Avatar answered Nov 15 '22 14:11

ildjarn


Googletest release 1.8.1 fixes this issue (in combination with VS2017 15.8.5).

like image 3
Petr Vepřek Avatar answered Nov 15 '22 14:11

Petr Vepřek