0

While trying to build my small test I encounter an error I don't understand why it shouldn't work. I'm using Eclipse and Cygwin. The Header and the Source files are separated into different Folders and I put them also into the Cygwin include folders.

Console log

16:05:41 **** Incremental Build of configuration Debug for project Testarea ****
make all 
Building target: Testarea.exe
Invoking: Cygwin C++ Linker
g++  -o "Testarea.exe"  ./Source/lint.o ./Source/tester.o   
./Source/tester.o: In function `main':
/cygdrive/d/CWork/Testarea/Debug/../Source/tester.cpp:4: undefined reference to `lint::lint()'
/cygdrive/d/CWork/Testarea/Debug/../Source/tester.cpp:4:(.text+0x20): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `lint::lint()'
collect2: error: ld returned 1 exit status
make: *** [makefile:47: Testarea.exe] Error 1

16:05:41 Build Finished (took 348ms)

tester.cpp

#include <iostream>
#include <lint.h>
int main(){
    lint* a = new lint();
    std::cout << "hallo";
    return 0;
}

lint.cpp

class lint{
    private:
        int* a;
    public:
        lint(){
            a = new int();
        };
        lint(int b){
            a = new int(b);
        };
        lint(lint& b){
            a = new int(b.value());
        };
        int value(){
            return *a;
        };
};

lint.h

#ifndef HEADER_LINT_H_
#define HEADER_LINT_H_
class lint{
    public:
        lint();
        lint(int b);
        lint(lint& b);
        int value();
};
#endif
  • 1
    Aside: new is not your friend... you've memory leaks all over the shop. – UKMonkey Jan 25 '18 at 15:38
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) –  Jan 25 '18 at 15:40
  • Could you show the contents of the makefile? – amc176 Jan 25 '18 at 15:41
  • Try deleting ./Source/lint.o and ./Source/tester.o. Maybe the timestamps on your files are screwy. – john Jan 25 '18 at 15:42
  • Your lint.cpp is wrong. Put it's content into lint.h –  Jan 25 '18 at 15:43

1 Answers1

1

Your problem is that you've got 2 classes there. One called lint and the other called lint but only available in the lint.cpp file.

Implementations are done:

#include "lint.h"
lint::lint() {}

and so forth.

UKMonkey
  • 6,941
  • 3
  • 21
  • 30