0

It's the first time I make mock object in QT. I'm trying using Gmock, but I don't know how to using it. Now, I create project TestGmock (QT Application) in QT, and I copy include folder in gmock-1.7.0 ( download it from https://code.google.com/) to TestGmock project directory ( and the same with gtest ). In class main :

#include <QCoreApplication>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
int main(int argc, char *argv[])
{
    testing::InitGoogleMock (&argc, argv);
    return RUN_ALL_TESTS();
}

But error :

  • C:\Qt\Qt5.2.1\Tools\QtCreator\bin\TestGmock\main.cpp:6: error: undefined reference to `testing::InitGoogleMock(int*, char**)'
  • C:\Qt\Qt5.2.1\Tools\QtCreator\bin\TestGmock\gtest\gtest.h:2288: error:undefined reference to `testing::UnitTest::GetInstance()'
  • C:\Qt\Qt5.2.1\Tools\QtCreator\bin\TestGmock\gtest\gtest.h:2288: error:undefined reference to `testing::UnitTest::Run()' collect2.exe:-1:
  • error: error: ld returned 1 exit status

Please help me using gmock and gtest in QT.

273K
  • 29,503
  • 10
  • 41
  • 64
Hien Ngo
  • 253
  • 5
  • 18

1 Answers1

0

This error is caused the fact, that Qt Creator couldn't find Gmock library. There is no need to put it in your project (or Qt installation) directory, but you should add INCLUDEPATH and LIBS options in .pro file. Look at Adding external library into Qt Creator project.

Community
  • 1
  • 1
trivelt
  • 1,913
  • 3
  • 22
  • 44
  • I try using INCLUDEPATH += C:\gmock\gtest\include\ and INCLUDEPATH += C:\gmock\include\ (gmock folder i extracted from gmock-1.7.0 ) But it's not ok. – Hien Ngo Oct 01 '14 at 04:40
  • When I includePath, but another error : error: No rule to make target '../TestGmock/gmock/gmock.h', needed by 'debug/main.o'. Stop. – Hien Ngo Oct 01 '14 at 04:47
  • Have you tried to invoke `qmake` manually and rebuild your project? Is that error occur also in release mode? – trivelt Oct 01 '14 at 06:50