gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 09:44:29 27 4
gpt4 key购买 nike

出于某种原因,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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com