C++ Header and Source Directories
I have the following files:
listDriverTest.cpp src/List.cpp headers/List.h
The include in List.cpp is
The include in listDriverTest.cpp is
When I compile with the following statement,
g++ listDriverTest.cpp "src/List.cpp"
I end up with a fair number of 'undefined reference' errors, e.g.
listDriverTest.cpp:(.text+0x81): undefined reference to `List<int>::List()' listDriverTest.cpp:(.text+0x8f): undefined reference to `List<int>::add(int)' listDriverTest.cpp:(.text+0x9d): undefined reference to `List<int>::add(int)' ...
How should I properly use includes and compile these three files in order for the compilation to work properly? I have gotten listDriverTest.cpp to compile and run properly with all the files in the same directory, but not when they're broken up like this.
See my answer in Must a child of a template class also be a template class?.
It is probably a different question, but the same answer applies.
It looks like the object file produced by compiling src/List.cpp already contains the specialization List, but it's in a different directory than the object file of listDriversTest.cpp. Hence, the linker cannot find it.
Of course, this depends on how you've organized your template code.
Your program compiled properly on my machine. Just remove the double quotes around src/List.cpp I think your problem is something else.
I added a function void list(void) in list.cpp which printed "list". The same signature was added to list.h.