undefined reference to class template

Kapps via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 23 01:42:10 PST 2014


On Friday, 14 November 2014 at 23:29:34 UTC, Satoshi wrote:
> Hi, Im using GDC 4.9.0 compiler. I have template classes like 
> "public class LinkedList(T) {...}" and when I try compile it 
> together, everything works fine. But when I compile every 
> source file to separate object file and link it together with 
> ld Ill get errors like:
>
> "/os/KernelLand/Kernel/TaskManager/Thread.d:99: undefined 
> reference to 
> `_D7Library10LinkedList45__T10LinkedListTC11TaskManager6Thread6ThreadZ10LinkedList6__ctorMFNaNbNfZC7Library10LinkedList45__T10LinkedListTC11TaskManager6Thread6ThreadZ10LinkedList'"
>
> Im compiling it with command like:
> gdc -mcmodel=kernel -nostdlib -mno-red-zone -Wall -masm=intel 
> -frelease -finline-functions -O3 -o obj-x86_64/abc.d.o -c abc.d
>
> Here is
> full error log http://pastebin.com/SjnYjqKh
>
> makefile 
> https://github.com/Bloodmanovski/Trinix/blob/dc80f3197f59fe96e9f4e29cea670ff2c7eaa342/KernelLand/Kernel/Makefile#L104
>
> LinkedList class 
> https://github.com/Bloodmanovski/Trinix/blob/dc80f3197f59fe96e9f4e29cea670ff2c7eaa342/KernelLand/Kernel/Library/LinkedList.d
>
>
> Can anyone help me how to solve this problem? Thanks
> (Sorry for bad english)

Sounds like you're not passing in LinkedList.d while compiling a 
file that uses it. You need to include all used files, including 
imports, on the command line when compiling. The undefined 
reference indicates it can't find the source code or di file 
containing LinkedList. Tools like rdmd do this for you by looking 
at the imports used automatically.

If not that, I'm not sure if this will help, but try using 
-femit-templates (similar to -allinst in DMD I believe?).

Besides that, all I can really suggest is double checking that 
you're actually including the object file containing LinkedList 
when you're linking and the source file when compiling.


More information about the Digitalmars-d-learn mailing list