For few days I'm trying to compile one project written in C++ using Code::Blocks IDE (on Linux, Ubuntu 64-bit). Code is valid but there are some linker errors. I noticed that I get errors 'undefined reference' for functions which are not inline defined in classes and are in other files (class is i *.h file and definitions on these functions are in *.cpp). I tried to write my own Makefile but it didn't help.
Makefile:
all: project
project: main.o DList.o Person.o
g++ main.o DList.o Person.o -o project
main.o: main.cpp
g++ -c main.cpp
DList.o: include/DList.cpp
g++ -c include/DList.cpp
Person.o: include/Person.cpp
g++ -c include/Person.cpp
clean:
rm -rf *.o
I don't know what should I do although I read some about these errors on the net.
// EDIT I changed Object.cpp and Object.h to Person.cpp and Person.h, moved *.cpp files to main directory and changed #include paths in *.cpp files.
Errors:
obj/Debug/main.o||In function `main':|
...main.cpp|19|undefined reference to `DListIterator<Person>::go(int)'|
...main.cpp|20|undefined reference to `std::basic_ostream<char, std::char_traits<char> >& operator<< <Person>(std::basic_ostream<char, std::char_traits<char> >&, DList<Person>&)'|
...main.cpp|21|undefined reference to `DList<Person>::~DList()'|
...main.cpp|21|undefined reference to `DList<Person>::~DList()'|
obj/Debug/main.o||In function `DList<Person>::insert(Person&)':|
...include/DList.h|45|undefined reference to `DList<Person>::insert(Person&, DListIterator<Person>&)'|
||=== Build finished: 5 errors, 0 warnings ===|
It makes no difference if I build starting make in command line or using Build function in Code::Blocks.
When I copied all code from *.cpp files to *.h files, compiler returned no errors, so I think that it's only linker problem.
DList.o Object.o main.o..cppfiles corresponding to one of the.ofiles you are linking.