0

I'm trying to use (compile) google test, but having troubles.

I have 1 exe project and another project (google unit test) which have tests for some classes of the first project.

I have tried to use the info from: C++ unit test start guide, how to set up Google Test

I have 2 c++ projects in my workspace:

  1. Exe project name: Tester

    • src folder which contains CElement.cpp, CElement.h, Main.cpp
  2. Google test project (exe) name: GoogleTestTester

    • gtest_src folder (contains the gtest)
    • TestElement folder (contains my tests classes)
    • Test1.cpp:

    Test(MyAppTtests, name) { CElement* pElm = new CElement();

    //..
    

    }

I'm getting link error (in the GoogleTestTester project): undefined reference to CElement::CElement()

  • I have include of "CElement.h" in Test1.cpp
  • In the project properties I have include path to the TestElement folder (which contains CElement.h file)

How can I fix it ?

user3668129
  • 4,318
  • 6
  • 45
  • 87
  • Possible duplicate of [How to test an EXE with Google Test?](http://stackoverflow.com/questions/23088252/how-to-test-an-exe-with-google-test) – Mike Kinghan Apr 21 '17 at 17:33

1 Answers1

0

Have the test project compile CElement.cpp and link the resulting object into the test executable.

If this does not help, or if you do this already, then maybe you declare CElement::CElement() in CElement.h, but do not define it in CElement.cpp.

If this does not help: Your description sounds like you have two sets of the CElement files - one set in Tester/src, and a copy of this set in GoogleTestTester/TestElement. Maybe the copies have diverged and you edited one set but not the other.

Ludwig Schulze
  • 2,155
  • 1
  • 17
  • 36