gcc 包含“#include〈gtest/gtest.h>”头文件时出现编译错误

bwntbbo3  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(362)

当我编译traingl e_test. cpp程序时,当gtest. h头文件包含在该文件中时,我得到以下错误。

  1. In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\gtest-message.h:55:0,
  2. from c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\gtest-assertion-result.h:46,
  3. from c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\gtest.h:59,
  4. from traingle_test.cpp:2:
  5. c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h:1238:8: error: 'mutex' in namespace 'std' does not name a type
  6. std::mutex mu_;
  7. ^~~~~
  8. c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h:1239:8: error: 'condition_variable' in namespace 'std' does not name a type
  9. std::condition_variable cv_;
  10. ^~~~~~~~~~~~~~~~~~
  11. c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h: In member function 'void testing::internal::Notification::Notify()':
  12. c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h:1225:21: error: 'mutex' is not a member of 'std'
  13. std::lock_guard<std::mutex> lock(mu_);
  14. ^~~
  15. c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h:1225:21: error: 'mutex' is not a member of 'std'
  16. c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h:1225:31: error: template argument 1 is invalid
  17. std::lock_guard<std::mutex> lock(mu_);

错误讯息

traingle_test.cpp

  1. #include "traingle.h"
  2. #include <gtest/gtest.h>
  3. namespace {
  4. TEST (TraingleTest, InvalidSides){
  5. EXPECT_EQ(-1, TypeOfTraingle(-10, 20, 30));
  6. EXPECT_EQ(-1, TypeOfTraingle(10, -20, 30));
  7. EXPECT_EQ(-1, TypeOfTraingle(3, 4, -8));
  8. }
  9. }

traingle.cpp

  1. #include "traingle.h"
  2. /* Return values
  3. 1 for equilateral, 2 for isosceles, 3 for scalan
  4. 0 for traingle can't be formed with given sides
  5. -1 if any side value is invalid, say -ve
  6. */
  7. int TypeOfTraingle(int a, int b, int c){
  8. if(a<0 || b<0 || c<0)
  9. return -1;
  10. if(!(a+b > c && b + c > a && a + c > b))
  11. return 0;
  12. else if (a==b && b==c)
  13. return 2;
  14. else
  15. return 3;
  16. }

traingle.h

  1. #ifndef __TRIANGLE_H
  2. #define __TRIANGLE_H
  3. int TypeOfTraingle(int, int, int);
  4. #endif

我这里有3个文件traingle.cpp(计算在这里完成),traingle_test.cpp(测试用例编写)和traingle.h(包含函数声明)。测试用例文件需要与traingle.cpp链接,输出是多少测试用例通过,基于测试用例值(x,y,z)的三角形类型(等边、等腰和不等边三角形)将显示为下图所示

hgc7kmma

hgc7kmma1#

您的MinGW GCC(版本6.3.0)非常旧。
您将需要一个MinGW-w 64,这是建立与POSIX线程支持。
可从https://winlibs.com/下载独立版本(32位和64位Windows分别下载)

相关问题