GMock 不编译 - GTEST_EXCLUSIVE_LOCK_REQUIRED似乎没有定义
GMock doesn't compile - GTEST_EXCLUSIVE_LOCK_REQUIRED seems to not be defined
我正在尝试构建一个简单的模拟类
#include "interpolation.hpp"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
class MockInterp1D : public Interp1DBase {
public:
MOCK_METHOD1(evaluateAt, double(double));
MOCK_METHOD2(evaluateAt, double(double, int));
};
基于以下基本类
class Interp1DBase {
public:
virtual double evaluateAt(double) const = 0;
virtual double evaluateAt(double, int) const = 0;
virtual ~Interp1DBase() { };
};
使用Google Mocks。当我试图编译使用该mock的测试时,我得到了以下错误:
In file included from /usr/include/gmock/gmock-generated-function-mockers.h:43:0,
from /usr/include/gmock/gmock.h:61,
from /home/tlycken/exjobb/Code/alpha-orbit-follower/test/interpolation/interpolation-mocks.hpp:4,
from /home/tlycken/exjobb/Code/alpha-orbit-follower/test/physics/B-field-tests.hpp:6,
from /home/tlycken/exjobb/Code/alpha-orbit-follower/test/physics/B-field-tests.cpp:2:
/usr/include/gmock/gmock-spec-builders.h:134:41: error: expected ‘;’ at end of member declaration
bool VerifyAndClearExpectationsLocked()
^
然后是数百个类似的语法或定义错误,所有错误都指向GMock中的文件。
我查看了gmock-spec-builder.h:134
,发现了以下内容(在某些上下文中):
// Verifies that all expectations on this mock function have been
// satisfied. Reports one or more Google Test non-fatal failures
// and returns false if not.
bool VerifyAndClearExpectationsLocked()
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
这让我相信CCD_ 2可能是一个由于某种原因没有定义的宏。事实上,在挖掘了gmock/gmock.h
或gtest/gtest.h
中包含的所有头文件之后,我仍然没有找到该宏的定义。
我在这里做错了什么?
更新:
我已经能够生成一个甚至简单的最小示例:
// in file mock-test.cpp
#include <gmock/gmock.h>
// Yeah, that's the only content
使用编译
g++ -o mock-test.o -c mock-test.cpp
导致相同的错误。
我通过sudo apt-get install google-mock
安装了GMock,它在/usr/src
下给了我一个文件夹,在那里我可以运行cmake .
,然后运行make
来生成库文件,并将其复制到/usr/lib
。头文件已经在/usr/include
中了,所以我没有手动对它们做任何操作。
当我尝试使用gmock 1.7和gtest 1.6进行编译时,我也遇到了同样的错误。请确保您使用的是相同版本的gtest。
我不知道如何在gcc
中使用g-mock。但基本上我们在这样的窗口中使用。你的类定义是正确的。你用过这样的功能吗
EXPECT_CALL(classobj, exact functionname as it looks in definition).AtLeast(Times(0)).Return(0);
然后
classobj.exact functionname as it looks in definition()
试试这个,我觉得它应该有效。如果你想详细了解它,请告诉我,我会用一些典型的例子来扩展它。
有适当的来源&/usr/src/gmock文件夹中的标头。
你的工作只是覆盖文件夹的全部内容:
/usr/src/gmock/gtest/src->/usr/src/gtest/src/usr/src/gmock/gtest/cmake->/usr/src/gtest/cmake/usr/src/gmock/gtest/CMakeLists.txt->/usr/src/gtest/CMakeLists.txt/usr/src/gmock/gtest/include/gtest->/usr/include/gtest/
- 在提升multi_index容器中,是否定义了"default index"?
- #定义c-预处理器常量..我做错了什么
- 用C++中的一个变量定义一个常量
- 部分定义/别名模板模板参数
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- #为""定义宏;静态";针对不同的上下文
- 如何确保C++函数在定义之前声明(如override关键字)
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 当类在C++中定义时,有什么方法可以"register"类吗?
- 在命名空间中定义函数还是限定函数
- 此代码是否违反一个定义规则
- 编译C++时未定义的引用
- 不同翻译单元中不可重载的非内联函数定义
- 为什么在定义函数之前先声明它
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- 在类定义之后定义一个私有方法
- 使用用户定义函数的字符串反转
- 用户定义函数中的指针和输入
- vscode g++链路故障:体系结构x86_64的未定义符号
- 当运行时库不存在时显示(自定义"required"错误?