vendredi 18 mai 2018

CXXTEST undefined reference to... when building

I've been trying using the CXXTEST framework to test a calcuator. After i finished working on the Calculator.h and Calculator.cpp files i launched the command

cxxtestgen --error-printer -o test.cpp TestCalculator.h

Then i tried to build test.cpp

g++ test.cpp

but it gives me this message:

/tmp/ccgDQQr5.o: In function `TestCalculator::test_global_Calculator_Calculator()':
test.cpp:(.text._ZN14TestCalculator33test_global_Calculator_CalculatorEv[_ZN14TestCalculator33test_global_Calculator_CalculatorEv]+0x23): undefined reference to `Calculator::Calculator()'
/tmp/ccgDQQr5.o: In function `TestCalculator::test_global_Calculator_Calculator_int()':
test.cpp:(.text._ZN14TestCalculator37test_global_Calculator_Calculator_intEv[_ZN14TestCalculator37test_global_Calculator_Calculator_intEv]+0x28): undefined reference to `Calculator::Calculator(int)'
/tmp/ccgDQQr5.o: In function `TestCalculator::testSum()':
test.cpp:(.text._ZN14TestCalculator7testSumEv[_ZN14TestCalculator7testSumEv]+0x28): undefined reference to `Calculator::Calculator(int)'
test.cpp:(.text._ZN14TestCalculator7testSumEv[_ZN14TestCalculator7testSumEv]+0x39): undefined reference to `Calculator::sum(int)'
/tmp/ccgDQQr5.o: In function `TestCalculator::testSubtract()':
test.cpp:(.text._ZN14TestCalculator12testSubtractEv[_ZN14TestCalculator12testSubtractEv]+0x28): undefined reference to `Calculator::Calculator(int)'
test.cpp:(.text._ZN14TestCalculator12testSubtractEv[_ZN14TestCalculator12testSubtractEv]+0x39): undefined reference to `Calculator::subtract(int)'
/tmp/ccgDQQr5.o: In function `TestCalculator::testMul()':
test.cpp:(.text._ZN14TestCalculator7testMulEv[_ZN14TestCalculator7testMulEv]+0x28): undefined reference to `Calculator::Calculator(int)'
test.cpp:(.text._ZN14TestCalculator7testMulEv[_ZN14TestCalculator7testMulEv]+0x39): undefined reference to `Calculator::mul(int)'
collect2: error: ld returned 1 exit status

You can see my TestCalculator.h (given by my teacher) below:

#ifndef TESTCALCULATOR_H_
#define TESTCALCULATOR_H_

#include <cxxtest/TestSuite.h>

#include "Calculator.h"

class TestCalculator : public CxxTest::TestSuite {
public:

    void setUp() {
        // objects used in test cases are created in this method
        // that is executed before all the other test methods
    }

    void test_global_Calculator_Calculator() {
        Calculator c;
        TS_ASSERT_EQUALS(c.getValue(), 0);
    }

    void test_global_Calculator_Calculator_int() {
        Calculator c(3);
        TS_ASSERT_EQUALS(c.getValue(), 3);
    }

    void testSum() {
        Calculator c(4);
        c.sum(3);
        TS_ASSERT_EQUALS(c.getValue(), 7);
    }

    void testSubtract() {
        Calculator c(5);
        c.subtract(3);
        TS_ASSERT_EQUALS(c.getValue(), 2);
    }

    void testMul() {
        Calculator c(7);
        c.mul(2);
        TS_ASSERT_EQUALS(c.getValue(), 14);
    }


};

#endif

How can i fix it?

Aucun commentaire:

Enregistrer un commentaire