I am working on coding all of the basic data structures in c++, and I have started with a LinkedList.
I have LinkedList.h which is the class definition for a LinkedList, with a nested LinkedNode class defintion. LinkedList.cpp and LinkedNode.cpp hold the actual function implementations for all of the functions in the classes as dictated by LinkedList.h. I also have LinkedListTests.h and LinkedListTests.cpp, where LinkedListTests.h has a set of functions which test my LinkedList implementation, and LinkedListTests.cpp has a main function which invokes the functions from LinkedListTests.h.
All of the .cpp files have:
#include "LinkedList.h"
in their headers, and LinkedListTests.cpp also has:
#include "LinkedListTests.h"
in it.
This is the makefile I created to compile and link the entire project together:
LinkedList: LinkedListTests.o LinkedList.o LinkedNode.o
g++ LinkedListTests.o LinkedList.o LinkedNode.o -o LinkedList
LinkedListTests.o: LinkedListTests.cpp LinkedListTests.h LinkedList.h
g++ -c LinkedListTests.cpp
LinkedList.o: LinkedList.cpp LinkedList.h
g++ -c LinkedList.cpp
LinkedNode.o: LinkedNode.cpp LinkedList.h
g++ -c LinkedNode.cpp
clean:
rm *.o LinkedList
Any help as to why I get undefined reference errors? I believe all of the .cpp files should be compiled and linked together, but that doesn't appear to be the case.
For reference, I am compiling and running with g++ on a Kali Linux virtual machine.