English 中文(简体)
当我 # 包括“ gmock/ gmock. h” 时编辑错误
原标题:Compile error when I #include "gmock/gmock.h"

我试图将googlemock 融入我的测试中。我已经成功地在谷歌中创建和运行了测试,现在也在尝试在测试中逐步添加 gmock 功能,但我遇到了一个我完全不理解的编译错误。

我不是试图使用或定义被嘲笑的类, 或使用任何 gmock.h 提供的 gmock.h 。 在我( 以前工作过的) 测试的顶部。 cpp 文件

#include "gmock/gmock.h"

我得到编译错误:

gmock/ gmock- matchers.h( 2497) : 错误 C2059: 语法错误: 大小

gmock/gmock-matchers.h(2505) : see reference to class template instantiation testing::internal::ElementsAreMatcherImpl being compiled

gmock/gmock- matchers.h(2497):误差C2059:语法错误:)

gmock/gmock-matchers.h(2497) : error C2143: syntax error : missing ) before {

gmock/gmock-matchers.h(2497) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

gmock/gmock-matchers.h(2499) : warning C4183: Message : missing return type; assumed to be a member function returning int

我在 Windows 7 上用 nmake/ vc+++ 来编译这个文件,我可以理解为什么我只要在测试文件中添加核心 gmock 包含文件, 就能得到这些编译错误。 有人见过这种事吗?

最佳回答
  1. Did you init google mock with InitGoogleMock(&__argc, __argv) in test project s main function?
  2. You should include only "gmock/gmock.h" in your test files (and where you call InitGoogleMock) - no need for inclusion of gtest.h.
  3. Have you updated your googletest library to googlemock. (https://github.com/google/googletest)

如果上述所有事情都属实,就应该奏效。

问题回答

在使用gestest和gmock之前要先确保事情的准确性。

  1. Include the gmock lib in Android.bp file.
  2. Include the header "external/googletest/googlemock/include" in include_dirs in Andoird.bp.
  3. Initialize the gmock and gtest in your test main function.
    testing::InitGoogleTest(&argc, argv);
    testing::InitGoogleMock(&argc, argv);
#include <iostream>
#include "gmock/gmock.h"

template <typename T>
class Foo : private T {
public:
  void foo() {
    T::bar();
  }

};

class Bar {
public:
  void bar() {
    std::cout << "Hey there!" << std::endl;
  }
};



int main() {
  Foo<Bar> f;
  f.foo();
}

template <typename T>
class Foo : private T {
public:
  void foo() {
    T::bar();
  }
};

class Bar {
public:
  void bar() {
    std::cout << "Hey there!" << std::endl;
  }
};



int main() {
  Foo<Bar> f;
  f.foo();
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签