3.3 Compiling with class templates

Let us consider the files in listings 3 (ll.h), 4 (ll.cc) and 5 (test.cc).

We can compile ll.cc and test.cc individually, using the following commands:

g++ -g -c test.cc  
g++ -g -c ll.cc

Then, we can link the two object files, using the following command:

g++ -g test.o ll.o

But the linker will complain that methods of the template class LinkedList<int> are not found!

We can use the following command to examine the object file ll.o:

objdump -D ll.o

We’ll find that there is no subroutine definitions!

What is going on?