std::tr1 with visual studio 2017
Asked Answered
P

2

15

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?

Phyllis answered 17/3, 2017 at 0:22 Comment(0)
O
20

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 ;-]

Omarr answered 17/3, 2017 at 0:27 Comment(1)
Thanks. I opted for _HAS_TR1_NAMESPACE option and it worked.Phyllis
M
5

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

Madelina answered 22/9, 2018 at 15:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.