Hello,

I just posted a different question about the same testing code here.

My test suite includes a class called TestOutgoingCall, which tests a class called -- surprise surprise -- OutgoingCall. That class lives one directory up. As a convenience, therefore, I added .. to the INCLUDEPATH of my test .pro file:

Qt Code:
  1. QT += core testlib
  2. TEMPLATE = app
  3. TARGET = test
  4. INCLUDEPATH += . ..
  5.  
  6. # Input
  7. SOURCES += \
  8. main.cpp \
  9. testoutgoingcall.cpp \
  10. testscopelock.cpp
  11.  
  12. HEADERS += \
  13. testoutgoingcall.h \
  14. testscopelock.h \
  15. testcase.h
To copy to clipboard, switch view to plain text mode 

Here is testoutgoingcall.h:

Qt Code:
  1. #ifndef TESTOUTGOINGCALL_H
  2. #define TESTOUTGOINGCALL_H
  3.  
  4. #include "testcase.h"
  5.  
  6. class OutgoingCall;
  7.  
  8. class TestOutgoingCall : public TestCase
  9. {
  10. Q_OBJECT
  11. private slots:
  12. void initTestCase();
  13. void cleanupTestCase();
  14.  
  15. private:
  16. OutgoingCall *call;
  17. };
  18.  
  19. #endif // TESTOUTGOINGCALL_H
To copy to clipboard, switch view to plain text mode 

and here is the .cpp file:

Qt Code:
  1. #include "testoutgoingcall.h"
  2.  
  3. #include "OutgoingCall.h"
  4. #include "OutgoingCall.cpp" // FIXME WHY DO WE NEED THIS TO COMPILE?! 07.31.15
  5.  
  6. void TestOutgoingCall::initTestCase() {
  7. call = new OutgoingCall("", "");
  8. }
  9.  
  10. void TestOutgoingCall::cleanupTestCase() {
  11. delete call;
  12. }
To copy to clipboard, switch view to plain text mode 

As you can see, the implementation is as yet trivial, which is fine. The problem is that if I remove #include "OutgoingCall.cpp" I get the following compiler errors:

Qt Code:
  1. Undefined symbols for architecture x86_64:
  2. "OutgoingCall::OutgoingCall(QString, QString)", referenced from:
  3. TestOutgoingCall::initTestCase() in testoutgoingcall.o
  4. ld: symbol(s) not found for architecture x86_64
  5. clang: error: linker command failed with exit code 1 (use -v to see invocation)
  6. make: *** [test.app/Contents/MacOS/test] Error 1
  7. 15:43:14: The process "/usr/bin/make" exited with code 2.
  8. Error while building/deploying project test (kit: Desktop Qt 5.5.0 clang 64bit)
  9. When executing step "Make"
To copy to clipboard, switch view to plain text mode 

The constructor for Outgoing call takes two QStrings. Everything works when I un-comment that include.

What is going on here? I'm fairly certain that including a .cpp file after the .h file is the Wrong Way To Do It.

Any insight is appreciated.

Thank you!