Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

first try with CppUnit: undefined reference to `TestCalculator::TestCalculator()

Help
longii
2013-12-09
2013-12-10
  • longii
    longii
    2013-12-09

    Hi,

    I'm a newcomer to CppUnit and for that, I followed a basic introduction at http://linuxtortures.blogspot.de/2012/04/unit-testing-with-cppunit-and-eclipse.html

    Unfortunately at the linking stage I get the error
    undefined reference to `TestCalculator::TestCalculator()
    Seems to be related to linking, but I have no clue why.

    Any help is appreciated! Many thanks!!!

    IDE is Eclipse

    11:58:57 * Incremental Build of configuration Debug for project CppUnit_Test_no1 *
    Info: Internal Builder is used for build
    g++ "-LC:\Users\jumo\.eclipse\cppunit-1.12.1\src\cppunit\.libs" -o CppUnit_Test_no1.exe "src\Test_MainRunner.o" "src\TestCalculator.o" "src\Calculator.o" -lcppunit
    src\Test_MainRunner.o: In function main': C:\Users\jumo\workspace\CppUnit_Test_no1\Debug/../src/Test_MainRunner.cpp:36: undefined reference toTestCalculator::TestCalculator()'

    Test_MainRunner.cpp:

    int main() {
    cout << "CppUnit My Test no1" << endl;
    CppUnit::TextUi::TestRunner runner;
    runner.addTest( new TestCalculator() ); <== here the error comes
    ...

    TestCalculator.h:

    ...
    class TestCalculator : public CppUnit::TestCase {
    public:
    TestCalculator();
    virtual ~TestCalculator();
    void runTest() {
    Calculator myCalculator;
    CPPUNIT_ASSERT( myCalculator.add(3,6)==9 );
    }
    ...

    TestCalculator.cpp

    inline TestCalculator::TestCalculator() {}

     
  • longii
    longii
    2013-12-10

    Problem solved: missing declaration (not related anyhow to CppUnit)

    wrong:
    class Calculator {
    public:
    Calculator();
    ...

    correct:
    class Calculator {
    public:
    Calculator(){};
    ...