我正在尝试在Windows中使用Qt Creator
进行谷歌模拟测试,但结果却出现了许多不同的undefined reference
错误。
我在Linux上尝试过,并且可以正常工作。对于Windows,我不知道gmock
设置是否错误。
这是在MOCK_CONST_METHOD2
,MOCK_METHOD2
,MOCK_METHOD1
和前两个EXPECT_CALL
上有问题的代码。并且在gmock
头文件上也有问题。
main.cpp
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "mail_service.hpp"
#include "warehouse.hpp"
#include "order.hpp"
using ::testing::Return;
using ::testing::_; // Matcher for parameters
/** \brief Mock for the warehouse interface.
* \author David Stutz
*/
class MockWarehouse : public Warehouse
{
public:
// see https://github.com/google/googletest/blob/master/googlemock/docs/ForDummies.md
MOCK_CONST_METHOD2(hasInventory, bool(int, std::string));
MOCK_METHOD2(remove, void(int, std::string));
};
/** \brief Mock for the mail service interface.
* \author David Stutz
*/
class MockMailService : public MailService
{
public:
MockMailService()
{
}
MOCK_METHOD1(send, void(std::string));
};
TEST(OrderTest, Fill)
{
MockWarehouse warehouse;
std::shared_ptr<MockMailService> mailService = std::make_shared<MockMailService>();
Order order(50, "Talisker");
order.setMailService(mailService);
EXPECT_CALL(warehouse, hasInventory(50, "Talisker"))
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(warehouse, remove(50, "Talisker"))
.Times(1);
EXPECT_CALL(*mailService, send(_)) // Not making assumptions on the message send ...
.Times(1);
ASSERT_TRUE(order.fill(warehouse));
}
/** \brief Main test entrance point.
* \param[in] argc
* \param[in] argv
*/
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
标头
mail_service.hpp
#ifndef MAIL_SERVICE_HPP
#define MAIL_SERVICE_HPP
class MailService
{
public:
/** \brief Send a mial.
* \param[in] message message to send
*/
virtual void send(std::string message) = 0;
};
#endif /* MAIL_SERVICE_HPP */
order.hpp
#ifndef ORDER_HPP
#define ORDER_HPP
#include <string>
#include <memory>
#include "warehouse.hpp"
#include "mail_service.hpp"
/** \brief An order of a product with quantity. */
class Order
{
public:
/** \brief Constructor.
* \param[in] quantity quantity requested
* \param[in] product product name requested
*/
Order(int quantity, std::string product)
{
this->quantity = quantity;
this->product = product;
}
/** \brief Set the mail service to use.
* \param[in] mailService the mail service to attach
*/
void setMailService(std::shared_ptr<MailService> mailService)
{
this->mailService = mailService;
}
/** \brief Fill the order given the warehouse.
* \param[in] warehouse the warehouse to use
* \return whether the operation was successful
*/
bool fill(Warehouse &warehouse)
{
if (warehouse.hasInventory(quantity, product))
{
// ...
warehouse.remove(quantity, product);
this->mailService->send("Order filled.");
return true;
}
else
{
// ...
this->mailService->send("Order not filled.");
return false;
}
}
private:
/** \brief Product name. */
std::string product;
/** \brief Quantity requested. */
int quantity;
/** \brief Mail service to use. */
std::shared_ptr<MailService> mailService;
};
#endif /* ORDER_HPP */
仓库
#ifndef WAREHOUSE_HPP
#define WAREHOUSE_HPP
#include <string>
/** \brief Warehouse interface. This interface is one of the collaborators of our SUT.
class Warehouse
{
public:
/** \brief Check whether the product in the given quantity is on stock.
* \param[in] quantity quantity requested
* \param[in] product product name
* \return whether the warehouse has the product on stock for the given quantity
*/
virtual bool hasInventory(int quantity, std::string product) const = 0;
/** \brief Remove the given quantity of the product from the warehouse.
* \param[in] quantity quantity to remove
* \param[in] product product name to remove
*/
virtual void remove(int quantity, std::string product) = 0;
};
#endif /* WAREHOUSE_HPP */
这是
makefile
这是.pro文件
CONFIG += console c++14
INCLUDEPATH += "google/gmock/include/"
INCLUDEPATH += "google/gmock/"
INCLUDEPATH += "google/gtest/include/"
INCLUDEPATH += "google/gtest/src/"
INCLUDEPATH += "google/gtest/"
INCLUDEPATH += "google/"
INCLUDEPATH += "../../"
SOURCES += \
order.cpp \
google/gtest/src/gtest.cc \
google/gtest/src/gtest-all.cc \
google/gtest/src/gtest-death-test.cc \
google/gtest/src/gtest-filepath.cc \
google/gtest/src/gtest-port.cc \
google/gtest/src/gtest-printers.cc \
google/gtest/src/gtest-test-part.cc \
google/gtest/src/gtest-typed-test.cc
HEADERS += \
mail_service.hpp \
order.hpp \
warehouse.hpp
这是编译输出错误:
10:53:25: Running steps for project GoogleMockTest2...
10:53:25: Configuration unchanged, skipping qmake step.
10:53:27: Starting: "C:\Qt\Qt5.9.3\Tools\mingw530_32\bin\mingw32-make.exe"
C:\Qt\Qt5.9.3\5.9.3\mingw53_32\bin\qmake.exe -o Makefile ..\GoogleMockTest2\GoogleMockTest2.pro -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"
C:/Qt/Qt5.9.3/Tools/mingw530_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/PB9N0052/Documents/build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug'
g++ -c -fno-keep-inline-dllexport -g -std=gnu++1y -Wextra -Wall -W -fexceptions -mthreads -DUNICODE -D_UNICODE -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I..\GoogleMockTest2 -I. -I..\GoogleMockTest2\google\googlemock\include -I..\GoogleMockTest2\google\googlemock -I..\GoogleMockTest2\google\googletest\include -I..\GoogleMockTest2\google\googletest\src -I..\GoogleMockTest2\google\googletest -I..\GoogleMockTest2\google -I..\..\..\PB9N0052 -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include\QtGui -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include\QtANGLE -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include\QtCore -Idebug -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\mkspecs\win32-g++ -o debug\warehouse.o ..\GoogleMockTest2\warehouse.cpp
g++ -c -fno-keep-inline-dllexport -g -std=gnu++1y -Wextra -Wall -W -fexceptions -mthreads -DUNICODE -D_UNICODE -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I..\GoogleMockTest2 -I. -I..\GoogleMockTest2\google\googlemock\include -I..\GoogleMockTest2\google\googlemock -I..\GoogleMockTest2\google\googletest\include -I..\GoogleMockTest2\google\googletest\src -I..\GoogleMockTest2\google\googletest -I..\GoogleMockTest2\google -I..\..\..\PB9N0052 -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include\QtGui -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include\QtANGLE -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\include\QtCore -Idebug -I..\..\..\..\Qt\Qt5.9.3\5.9.3\mingw53_32\mkspecs\win32-g++ -o debug\mail_service.o ..\GoogleMockTest2\mail_service.cpp
g++ -Wl,-subsystem,console -mthreads -o debug\GoogleMockTest2.exe debug/order.o debug/gtest-all.o debug/warehouse.o debug/mail_service.o -LC:\Qt\Qt5.9.3\5.9.3\mingw53_32\lib C:\Qt\Qt5.9.3\5.9.3\mingw53_32\lib\libQt5Guid.a C:\Qt\Qt5.9.3\5.9.3\mingw53_32\lib\libQt5Cored.a
debug/order.o: In function `ZN19OrderTest_Fill_Test8TestBodyEv':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/order.cpp:44: undefined reference to `testing::Matcher<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::Matcher(char const*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1416: undefined reference to `testing::Mock::UnregisterLocked(testing::internal::UntypedFunctionMockerBase*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1418: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEED1Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1414: undefined reference to `testing::internal::g_gmock_mutex'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1415: undefined reference to `testing::internal::UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1416: undefined reference to `testing::Mock::UnregisterLocked(testing::internal::UntypedFunctionMockerBase*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1418: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEC2Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1407: undefined reference to `testing::internal::UntypedFunctionMockerBase::UntypedFunctionMockerBase()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1407: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEED2Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1414: undefined reference to `testing::internal::g_gmock_mutex'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1415: undefined reference to `testing::internal::UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1416: undefined reference to `testing::Mock::UnregisterLocked(testing::internal::UntypedFunctionMockerBase*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1418: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEED1Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1414: undefined reference to `testing::internal::g_gmock_mutex'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1415: undefined reference to `testing::internal::UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1416: undefined reference to `testing::Mock::UnregisterLocked(testing::internal::UntypedFunctionMockerBase*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1418: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEC2Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1407: undefined reference to `testing::internal::UntypedFunctionMockerBase::UntypedFunctionMockerBase()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1407: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEED2Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1414: undefined reference to `testing::internal::g_gmock_mutex'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1415: undefined reference to `testing::internal::UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1416: undefined reference to `testing::Mock::UnregisterLocked(testing::internal::UntypedFunctionMockerBase*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1418: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEED1Ev':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1414: undefined reference to `testing::internal::g_gmock_mutex'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1415: undefined reference to `testing::internal::UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1416: undefined reference to `testing::Mock::UnregisterLocked(testing::internal::UntypedFunctionMockerBase*)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1418: undefined reference to `testing::internal::UntypedFunctionMockerBase::~UntypedFunctionMockerBase()'
debug/order.o: In function `ZN7testing8internal8MockSpecIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE18InternalExpectedAtEPKciSB_SB_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1271: undefined reference to `testing::internal::LogWithLocation(testing::internal::LogSeverity, char const*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE5TimesEi':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:932: undefined reference to `testing::Exactly(int)'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE8WillOnceERKNS_6ActionIS8_EE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1002: undefined reference to `testing::Exactly(int)'
debug/order.o: In function `ZN7testing8internal8MockSpecIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE18InternalExpectedAtEPKciSB_SB_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1271: undefined reference to `testing::internal::LogWithLocation(testing::internal::LogSeverity, char const*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE5TimesEi':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:932: undefined reference to `testing::Exactly(int)'
debug/order.o: In function `ZN7testing8internal8MockSpecIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE18InternalExpectedAtEPKciSB_SB_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1271: undefined reference to `testing::internal::LogWithLocation(testing::internal::LogSeverity, char const*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE5TimesEi':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:932: undefined reference to `testing::Exactly(int)'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE10InvokeWithERKSt5tupleIJiS7_EE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1529: undefined reference to `testing::internal::UntypedFunctionMockerBase::UntypedInvokeWith(void const*)'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE10InvokeWithERKSt5tupleIJiS7_EE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1529: undefined reference to `testing::internal::UntypedFunctionMockerBase::UntypedInvokeWith(void const*)'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE25ClearDefaultActionsLockedEv':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1560: undefined reference to `testing::Expectation::~Expectation()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1551: undefined reference to `testing::internal::UntypedFunctionMockerBase::MockObject() const'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1551: undefined reference to `testing::Mock::RegisterUseByOnCallOrExpectCall(void const*, char const*, int)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1558: undefined reference to `testing::internal::g_gmock_implicit_sequence'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1560: undefined reference to `testing::Expectation::Expectation(testing::internal::linked_ptr<testing::internal::ExpectationBase> const&)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1560: undefined reference to `testing::Sequence::AddExpectation(testing::Expectation const&) const'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1560: undefined reference to `testing::Expectation::~Expectation()'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1560: undefined reference to `testing::Expectation::~Expectation()'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE5TimesERKNS_11CardinalityE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:926: undefined reference to `testing::internal::ExpectationBase::UntypedTimes(testing::Cardinality const&)'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEC1EPNS0_18FunctionMockerBaseIS8_EEPKciRKS7_RKSt5tupleIJNS_7MatcherIiEENSI_IS7_EEEE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:894: undefined reference to `testing::internal::ExpectationBase::ExpectationBase(char const*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:894: undefined reference to `testing::internal::ExpectationBase::~ExpectationBase()'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEC1EPNS0_18FunctionMockerBaseIS8_EEPKciRKS7_RKSt5tupleIJNS_7MatcherIiEENSI_IS7_EEEE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:899: undefined reference to `testing::internal::ExpectationBase::CheckActionCountIfNotDone() const'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:904: undefined reference to `testing::internal::ExpectationBase::~ExpectationBase()'
debug/order.o: In function `ZN7testing8internal16TypedExpectationIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE9GetHandleEv':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1077: undefined reference to `testing::internal::UntypedFunctionMockerBase::GetHandleOf(testing::internal::ExpectationBase*)'
debug/order.o: In function `ZNK7testing8internal18FunctionMockerBaseIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE32UntypedDescribeUninterestingCallEPKvPSo':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1603: undefined reference to `testing::internal::UntypedFunctionMockerBase::Name() const'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE30UntypedFindMatchingExpectationEPKvPSB_PbPSoSE_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1630: undefined reference to `testing::internal::g_gmock_mutex'
debug/order.o: In function `ZNK7testing8internal18FunctionMockerBaseIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE32UntypedDescribeUninterestingCallEPKvPSo':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1603: undefined reference to `testing::internal::UntypedFunctionMockerBase::Name() const'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFviNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE30UntypedFindMatchingExpectationEPKvPSB_PbPSoSE_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1630: undefined reference to `testing::internal::g_gmock_mutex'
debug/order.o: In function `ZNK7testing8internal18FunctionMockerBaseIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE32UntypedDescribeUninterestingCallEPKvPSo':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1603: undefined reference to `testing::internal::UntypedFunctionMockerBase::Name() const'
debug/order.o: In function `ZN7testing8internal18FunctionMockerBaseIFbiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE30UntypedFindMatchingExpectationEPKvPSB_PbPSoSE_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1630: undefined reference to `testing::internal::g_gmock_mutex'
debug/order.o: In function `ZNK7testing8internal18FunctionMockerBaseIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE29FindMatchingExpectationLockedERKSt5tupleIJS7_EE':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1661: undefined reference to `testing::internal::g_gmock_mutex'
debug/order.o: In function `ZNK7testing8internal18FunctionMockerBaseIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE33FormatUnexpectedCallMessageLockedERKSt5tupleIJS7_EEPSoSE_':
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1110: undefined reference to `testing::internal::g_gmock_mutex'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1128: undefined reference to `testing::internal::ExpectationBase::AllPrerequisitesAreSatisfied() const'
C:\Users\PB9N0052\Documents\build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug/../GoogleMockTest2/google/gmock/include/gmock/gmock-spec-builders.h:1133: undefined reference to `testing::internal::ExpectationBase::FindUnsatisfiedPrerequisites(testing::ExpectationSet*) const'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [debug\GoogleMockTest2.exe] Error 1
mingw32-make: *** [debug] Error 2
Makefile.Debug:74: recipe for target 'debug\GoogleMockTest2.exe' failed
mingw32-make[1]: Leaving directory 'C:/Users/PB9N0052/Documents/build-GoogleMockTest2-Desktop_Qt_5_9_3_MinGW_32bit-Debug'
Makefile:36: recipe for target 'debug' failed
10:53:32: The process "C:\Qt\Qt5.9.3\Tools\mingw530_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project GoogleMockTest2 (kit: Desktop Qt 5.9.3 MinGW 32bit)
When executing step "Make"
10:53:32: Elapsed time: 00:07.
最佳答案
也许您忘记在源文件中添加gmock的“ .cc”文件。
因为在您的.pro文件中,您仅添加了gtest的“ .cc”文件。
我一直做的是,“添加现有文件”,然后查找gmock的src文件夹。
并添加.cc文件。
像这个样本:
SOURCES += \
../calculator.cpp \
../button.cpp \
main.cpp \
gtest/src/gtest.cc \
gtest/src/gtest-all.cc \
gtest/src/gtest-death-test.cc \
gtest/src/gtest-filepath.cc \
gtest/src/gtest-port.cc \
gtest/src/gtest-printers.cc \
gtest/src/gtest-test-part.cc \
gtest/src/gtest-typed-test.cc \
gmock/src/gmock-spec-builders.cc \
gmock/src/gmock-matchers.cc \
gmock/src/gmock-internal-utils.cc \
gmock/src/gmock-cardinalities.cc \
gmock/src/gmock-all.cc \
gmock/src/gmock.cc
关于c++ - Qt中的GMock和 undefined reference 错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57036608/