Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to both Conctructor and destructor

I'm trying to write unit test usig google test and google mock but I have little difficulties with that. I'm getting error ( which You can see below) I can't fix.

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

Here my AppMock.h file:

#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 file:

class Application {
   public:
      Application();
      ~Application();
      int Reset(int i, const char* chr)
}

Conctructor and destructor are defined in file app.cxx. Destructor is trivial:

//Deconstruction method
Application::~Application() {
    // release all resources before exit

} // end of ~Application()

DummyUT file:

#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
like image 810
szpic Avatar asked Nov 28 '25 18:11

szpic


1 Answers

As mentioned before you have to add another target for App:

app.o:   app.cpp

And TestCIPApp must depends on this:

TestCIPApp: DummyUT.o DummyClass.o testClass.o app.o

Now the objectfile is also there and the symbols can be found.

like image 132
KimKulling Avatar answered Dec 01 '25 08:12

KimKulling