当我编译traingl e_test. cpp程序时,当gtest. h头文件包含在该文件中时,我得到以下错误。
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\gtest-message.h:55:0,
from c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\gtest-assertion-result.h:46,
from c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\gtest.h:59,
from traingle_test.cpp:2:
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
std::mutex mu_;
^~~~~
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
std::condition_variable cv_;
^~~~~~~~~~~~~~~~~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h: In member function 'void testing::internal::Notification::Notify()':
c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h:1225:21: error: 'mutex' is not a member of 'std'
std::lock_guard<std::mutex> lock(mu_);
^~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h:1225:21: error: 'mutex' is not a member of 'std'
c:\mingw\lib\gcc\mingw32\6.3.0\include\gtest\internal\gtest-port.h:1225:31: error: template argument 1 is invalid
std::lock_guard<std::mutex> lock(mu_);
错误讯息
traingle_test.cpp
#include "traingle.h"
#include <gtest/gtest.h>
namespace {
TEST (TraingleTest, InvalidSides){
EXPECT_EQ(-1, TypeOfTraingle(-10, 20, 30));
EXPECT_EQ(-1, TypeOfTraingle(10, -20, 30));
EXPECT_EQ(-1, TypeOfTraingle(3, 4, -8));
}
}
traingle.cpp
#include "traingle.h"
/* Return values
1 for equilateral, 2 for isosceles, 3 for scalan
0 for traingle can't be formed with given sides
-1 if any side value is invalid, say -ve
*/
int TypeOfTraingle(int a, int b, int c){
if(a<0 || b<0 || c<0)
return -1;
if(!(a+b > c && b + c > a && a + c > b))
return 0;
else if (a==b && b==c)
return 2;
else
return 3;
}
traingle.h
#ifndef __TRIANGLE_H
#define __TRIANGLE_H
int TypeOfTraingle(int, int, int);
#endif
我这里有3个文件traingle.cpp(计算在这里完成),traingle_test.cpp(测试用例编写)和traingle.h(包含函数声明)。测试用例文件需要与traingle.cpp链接,输出是多少测试用例通过,基于测试用例值(x,y,z)的三角形类型(等边、等腰和不等边三角形)将显示为下图所示
1条答案
按热度按时间hgc7kmma1#
您的MinGW GCC(版本6.3.0)非常旧。
您将需要一个MinGW-w 64,这是建立与POSIX线程支持。
可从https://winlibs.com/下载独立版本(32位和64位Windows分别下载)