c++ - Windows GTest EXPECT_STREQ : error: no matching function for call to 'CmpHelperSTREQ'

标签 c++ windows mingw googletest clion

出于某种原因,GTest 在我的开发站上表现不佳。某些 ASSERT/EXPECT 测试正在运行,但我无法让字符串比较正常运行。这就是代码在 CLion 中的样子;注意错误弹出窗口:

enter image description here

底部还附上了编译时的错误输出。由于我在 Windows 10 上使用 JetBrains CLion,因此必须使用“MinGW Makefiles”CMake 生成器构建 GTest,然后使用 MinGW make(而不是 CMake 默认的 Visual Studio 生成器)。此外,我能找到的唯一可用资源是最新的 Github GTest master 分支;其 2016 年 11 月的最新版本将不会在 MinGW 的 Windows 上构建。

In file included from C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1874:0,
                 from C:\projects\gtest-test\tests\basic_test.cpp:4:
C:\projects\gtest-test\tests\basic_test.cpp: In member function 'virtual void basic_test_helloWorldEqualsHelloWorld_Test::TestBody()':
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest_pred_impl.h:147:45: error: no matching function for call to 'CmpHelperSTREQ(const char [7], const char [7], std::__cxx11::string&, std::__cxx11::string&)'
   GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
                                             ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest_pred_impl.h:77:52: note: in definition of macro 'GTEST_ASSERT_'
   if (const ::testing::AssertionResult gtest_ar = (expression)) \
                                                    ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest_pred_impl.h:162:3: note: in expansion of macro 'GTEST_PRED_FORMAT2_'
   GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
   ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1996:3: note: in expansion of macro 'EXPECT_PRED_FORMAT2'
   EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
   ^
C:\projects\gtest-test\tests\basic_test.cpp:14:5: note: in expansion of macro 'EXPECT_STREQ'
     EXPECT_STREQ(hello2, hello3);
     ^
In file included from C:\projects\gtest-test\tests\basic_test.cpp:4:0:
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1537:28: note: candidate: testing::AssertionResult testing::internal::CmpHelperSTREQ(const char*, const char*, const char*, const char*)
 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
                            ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1537:28: note:   no known conversion for argument 3 from 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' to 'const char*'
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1570:28: note: candidate: testing::AssertionResult testing::internal::CmpHelperSTREQ(const char*, const char*, const wchar_t*, const wchar_t*)
 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
                            ^
C:/PROGRA~2/GOOGLE~1/include/gtest/gtest.h:1570:28: note:   no known conversion for argument 3 from 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' to 'const wchar_t*'
tests\CMakeFiles\gtestTest_tests.dir\build.make:62: recipe for target 'tests/CMakeFiles/gtestTest_tests.dir/basic_test.cpp.obj' failed
mingw32-make.exe[3]: *** [tests/CMakeFiles/gtestTest_tests.dir/basic_test.cpp.obj] Error 1
mingw32-make.exe[2]: *** [tests/CMakeFiles/gtestTest_tests.dir/all] Error 2
CMakeFiles\Makefile2:1063: recipe for target 'tests/CMakeFiles/gtestTest_tests.dir/all' failed
mingw32-make.exe[1]: *** [tests/CMakeFiles/gtestTest_tests.dir/rule] Error 2
CMakeFiles\Makefile2:1075: recipe for target 'tests/CMakeFiles/gtestTest_tests.dir/rule' failed
Makefile:494: recipe for target 'gtestTest_tests' failed
mingw32-make.exe: *** [gtestTest_tests] Error 2

最佳答案

您尝试使用 EXPECT_STREQ 来比较两个 std::string,而在比较原始 C 字符串 (char*) 时应该使用它>).

Google Test Primer 中有一节

为了比较 std::string,您应该使用 EXPECT_EQ

关于c++ - Windows GTest EXPECT_STREQ : error: no matching function for call to 'CmpHelperSTREQ' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43763615/

相关文章:

c++ - 如何获取原始命令行参数

c - 通过 glfw 或 lungarg 为 code::blocks 设置 vulkan

c - 如何从文件中正确添加 gdi32.lib?

c++ - 使用动态参数创建线程

php - Apache:在此服务器上找不到请求的 URL。 Apache

windows - 从命令行更改 Windows 主机名

c++ - 未定义从dll引用非成员运算符

c++ - cin.ignore()为什么忽略getline输入的第一个字符?

c++ - 在许多不同的平台上使用 c/c++ 中的线程

c++ - 为什么 4 个进程比 4 个线程好?