对构造函数和析构函数的未定义引用
Undefined reference to both Conctructor and destructor
我正在尝试使用google test
和google mock
编写单元测试,但我对此没有什么困难。我得到一个错误(你可以看到下面),我不能修复。
DummyUT.o: In function `~MockApplicationClass':
srctest/../mocks/AppMock.h:15: undefined reference to `Application::~Application()'
srctest/../mocks/AppMock.h:15: undefined reference to `Application::~Application()'
DummyUT.o: In function `MockApplicationClass':
srctest/../mocks/AppMock.h:15: undefined reference to `Application::Application()'
srctest/../mocks/AppMock.h:15: undefined reference to `Application::~Application()'
collect2: ld returned 1 exit status
make: *** [TestApp] Error 1
我的AppMock.h文件:
#ifndef APPMOCK_H_
#define APPMOCK_H_
#include "../../app.hxx"
#include "gmock/gmock.h"
class MockApplicationClass: public Application
{
public:
MOCK_CONST_METHOD2(Reset, void(int i, const char* chr));
};
#endif /* APPMOCK_H_ */
here app.hxx文件:
class Application {
public:
Application();
~Application();
int Reset(int i, const char* chr)
}
构造函数和析构函数在文件app.cxx中定义。析构函数是平凡的:
//Deconstruction method
Application::~Application() {
// release all resources before exit
} // end of ~Application()
DummyUT文件:
#include <sys/types.h>
#include "../DummyClass.h" //path to code being tested
#include "../../app.hxx"
#include "../../testClass.h"
#include "../mocks/dummyMock.h" //path to mock
#include "../mocks/AppMock.h"
#include "../mocks/testMock.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::AllOf;
using ::testing::Ge;
using ::testing::Le;
TEST(Test, testaplikacji)
{
const char* a="abc";
MockApplicationClass theClass;
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
And Make file:
CXX=g++
GTEST_DIR = ../../../UTframework/gmock-1.7.0/gtest
GMOCK_DIR = ../../../UTframework/gmock-1.7.0/
EXXX_PATH_PRE = /home/XXX/dev/exxx
# flags
CPPFLAGS += -isystem $(GTEST_DIR)/include -isystem $(GMOCK_DIR)/include
CXXFLAGS += -g -Wall -Wextra -pthread
GMOCK_LIB = $(GMOCK_DIR)/make
# All tests produced by this Makefile. Remember to add new tests you
TESTS = TestApp
CPPFLAGS += -isystem /home/XXX/dev/exxx/target/dataserver/include
CPPFLAGS += -isystem ../../Conflib/include
CPPFLAGS += -isystem /home/XXX/dev/exxx/target/XX/include
# All Google Test headers. Usually you shouldn't change this
# definition.
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h
$(GTEST_DIR)/include/gtest/internal/*.h
# All Google Mock headers. Note that all Google Test headers are
# included here too, as they are #included by Google Mock headers.
# Usually you shouldn't change this definition.
GMOCK_HEADERS = $(GMOCK_DIR)/include/gmock/*.h
$(GMOCK_DIR)/include/gmock/internal/*.h
$(GTEST_HEADERS)
all: $(TESTS)
clean:
rm -f $(TESTS) *.o
TestCIPApp: DummyUT.o DummyClass.o testClass.o
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $^ -L$(GMOCK_LIB) -lgmock_main -o $@
DummyUT.o: srctest/DummyUT.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $^
DummyClass.o: DummyClass.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $^ -o $@
copy:
cp $(TESTS) ../../../UTBuildAll
如前所述,你必须为App添加另一个目标:
app.o: app.cpp
和TestCIPApp必须依赖于这个:
TestCIPApp: DummyUT.o DummyClass.o testClass.o app.o
现在objectfile也在那里,可以找到符号
相关文章:
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用