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 += core testlib
TEMPLATE = app
TARGET = test
INCLUDEPATH += . ..
# Input
SOURCES += \
main.cpp \
testoutgoingcall.cpp \
testscopelock.cpp
HEADERS += \
testoutgoingcall.h \
testscopelock.h \
testcase.h
QT += core testlib
TEMPLATE = app
TARGET = test
INCLUDEPATH += . ..
# Input
SOURCES += \
main.cpp \
testoutgoingcall.cpp \
testscopelock.cpp
HEADERS += \
testoutgoingcall.h \
testscopelock.h \
testcase.h
To copy to clipboard, switch view to plain text mode
Here is testoutgoingcall.h:
#ifndef TESTOUTGOINGCALL_H
#define TESTOUTGOINGCALL_H
#include "testcase.h"
class OutgoingCall;
class TestOutgoingCall : public TestCase
{
Q_OBJECT
private slots:
void initTestCase();
void cleanupTestCase();
private:
OutgoingCall *call;
};
#endif // TESTOUTGOINGCALL_H
#ifndef TESTOUTGOINGCALL_H
#define TESTOUTGOINGCALL_H
#include "testcase.h"
class OutgoingCall;
class TestOutgoingCall : public TestCase
{
Q_OBJECT
private slots:
void initTestCase();
void cleanupTestCase();
private:
OutgoingCall *call;
};
#endif // TESTOUTGOINGCALL_H
To copy to clipboard, switch view to plain text mode
and here is the .cpp file:
#include "testoutgoingcall.h"
#include "OutgoingCall.h"
#include "OutgoingCall.cpp" // FIXME WHY DO WE NEED THIS TO COMPILE?! 07.31.15
void TestOutgoingCall::initTestCase() {
call = new OutgoingCall("", "");
}
void TestOutgoingCall::cleanupTestCase() {
delete call;
}
#include "testoutgoingcall.h"
#include "OutgoingCall.h"
#include "OutgoingCall.cpp" // FIXME WHY DO WE NEED THIS TO COMPILE?! 07.31.15
void TestOutgoingCall::initTestCase() {
call = new OutgoingCall("", "");
}
void TestOutgoingCall::cleanupTestCase() {
delete call;
}
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:
Undefined symbols for architecture x86_64:
"OutgoingCall::OutgoingCall(QString, QString)", referenced from:
TestOutgoingCall::initTestCase() in testoutgoingcall.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test.app/Contents/MacOS/test] Error 1
15:43:14: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project test (kit: Desktop Qt 5.5.0 clang 64bit)
When executing step "Make"
Undefined symbols for architecture x86_64:
"OutgoingCall::OutgoingCall(QString, QString)", referenced from:
TestOutgoingCall::initTestCase() in testoutgoingcall.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test.app/Contents/MacOS/test] Error 1
15:43:14: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project test (kit: Desktop Qt 5.5.0 clang 64bit)
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!
Bookmarks