問題
編譯googletest開源項目巫击,始終有一個工程(gtest_unittest允乐,gtest自測工程)無法編譯通過畴椰。
項目地址:google/googletest
分支版本:1.8.x
編譯問題:
3>..\..\test\gtest_unittest.cc(7598): error C2653: '__gnu_cxx' : is not a class or namespace name
3>..\..\test\gtest_unittest.cc(7598): error C2065: 'hash_set' : undeclared identifier
3>..\..\test\gtest_unittest.cc(7598): error C2062: type 'int' unexpected
3>..\..\test\gtest_unittest.cc(7598): error C2039: 'value' : is not a member of '`global namespace''
3>..\..\test\gtest_unittest.cc(7598): error C2059: syntax error : ')'
3>..\..\test\gtest_unittest.cc(7598): error C2059: syntax error : ')'
3>..\..\test\gtest_unittest.cc(7598): error C2143: syntax error : missing ',' before ')'
3>..\..\test\gtest_unittest.cc(7600): error C2143: syntax error : missing ';' before '}'
3>..\..\test\gtest_unittest.cc(7604): error C2143: syntax error : missing ';' before '{'
環(huán)境
OS: Windows 10 家庭中文版
IDE: Visual Studio 2010 Ultimate
分析
出問題的代碼是這里瓣喊,提示__gun_cxx命名空間無法找到花履。
#if GTEST_HAS_HASH_SET_
EXPECT_TRUE(testing::internal::IsHashTable<__gnu_cxx::hash_set<int>>::value);
#endif // GTEST_HAS_HASH_SET_
在網(wǎng)上找了一些資料芽世,好像大家也都沒有遇到這個問題,這讓人很頭疼诡壁。
// Determines if hash_map/hash_set are available.
// Only used for testing against those containers.
#if !defined(GTEST_HAS_HASH_MAP_)
# if defined(_MSC_VER) && (_MSC_VER < 1900)
# define GTEST_HAS_HASH_MAP_ 1 // Indicates that hash_map is available.
# define GTEST_HAS_HASH_SET_ 1 // Indicates that hash_set is available.
# endif // _MSC_VER
#endif // !defined(GTEST_HAS_HASH_MAP_)
上面這段代碼應(yīng)該是已經(jīng)處理過了相關(guān)編譯的問題济瓢,但我的環(huán)境并不可以解決問題。
只能把GTEST_HAS_HASH_SET_強制設(shè)置為0妹卿,關(guān)閉對hash_set的支持了旺矾。
# define GTEST_HAS_HASH_SET_ 0 // Indicates that hash_set is available.