www.digitalmars.com         C & C++   DMDScript  

D - Link error using template in library - 1 attachment

I'm getting a linker error while trying to make
a library that uses a template.


---------------------------------------------------------
Here is the template library file: temp.d
---------------------------------------------------------

Z:\D\errreport1>type temp.d 

module temp;


template Foo(Type)
{
  bit isSorted(Type[] array, int delegate(Type a,Type b) cmp)
  {
    for(int i = 1; i < array.length; ++i)
    {
      if(cmp(array[i-1],array[i]) > 0)
        return false;
    }
        
    return true;
  }


  void insertionSort(Type array[], int delegate(Type a,Type b) cmp)
  in
  {
    assert(cmp);
  }
  out
  {
    assert(isSorted(array,cmp));
  }
  body
  {
    for (int i=1; i < array.length; i++)
    {
      Type index = array[i];
      int j = i;
      while ((j > 0) && cmp(index,array[j-1]) == -1)
      {
        array[j] = array[j-1];
        j = j - 1;
      }
      array[j] = index;
    }
  }
}

---------------------------------------------------------
Compile it and make it into a library
---------------------------------------------------------

Z:\D\errreport1>dmd -c temp.d 

Z:\D\errreport1>lib -c temp.lib temp.obj 
Digital Mars Librarian Version 8.00n
Copyright (C) Digital Mars 2000-2002 All Rights Reserved 
www.digitalmars.com
Digital Mars Librarian complete.  
---------------------------------------------------------
Here is the library that uses the template: usetemp.d
---------------------------------------------------------

Z:\D\errreport1>type usetemp.d 

module usetemp;


import temp;


alias instance Foo(int).insertionSort intSort;


void bar(int[] arr)
{
  intSort(arr,
    delegate int(int a,int b) 
    { 
      if(a < b) return -1; 
      else if(a == b) return 0; 
      else return 1; 
    });
}


---------------------------------------------------------
Compile it and make it into a library
---------------------------------------------------------

Z:\D\errreport1>dmd -c usetemp.d 

Z:\D\errreport1>lib -c usetemp.lib usetemp.obj 
Digital Mars Librarian Version 8.00n
Copyright (C) Digital Mars 2000-2002 All Rights Reserved 
www.digitalmars.com
Digital Mars Librarian complete.  
---------------------------------------------------------
Here is the test file
---------------------------------------------------------

Z:\D\errreport1>type err.d 


import usetemp;


int main(char[][] argv)
{
  int[] test;
  test ~= 5;
  test ~= 12;
  test ~= 1;
  test ~= 3;
  test ~= 15;
  test ~= 45;
  test ~= 12;
  test ~= 9;
  
  bar(test);
  
  return 0;
}

---------------------------------------------------------
Try to put it all together and get a linker error
---------------------------------------------------------

Z:\D\errreport1>dmd err.d usetemp.lib temp.lib 
Z:\tools\dmd\bin\link.exe err,,,usetemp.lib+temp.lib+user32+kernel32/noi;

OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved
   
temp.lib
 Warning 140: Library probably needs FIXLIB 
usetemp.lib(usetemp) 
 Error 42: Symbol Undefined _assert_temp
usetemp.lib(usetemp) 
 Error 42: Symbol Undefined _array_temp
--- errorlevel 2
---------------------------------------------------------
Try compiling in the template directly same problem
---------------------------------------------------------

Z:\D\errreport1>dmd err.d usetemp.lib temp.d 
Z:\tools\dmd\bin\link.exe err+temp,,,usetemp.lib+user32+kernel32/noi;

OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved
   
usetemp.lib(usetemp) 
 Error 42: Symbol Undefined _assert_temp
usetemp.lib(usetemp) 
 Error 42: Symbol Undefined _array_temp
--- errorlevel 2
---------------------------------------------------------
Finally this works
---------------------------------------------------------

Z:\D\errreport1>dmd err.d usetemp.d temp.d 
Z:\tools\dmd\bin\link.exe err+usetemp+temp,,,user32+kernel32/noi;
---------------------------------------------------------
DMD version
---------------------------------------------------------

Z:\D\errreport1>dmd
Digital Mars D Compiler Beta v0.61
Copyright (c) 1999-2003 by Digital Mars written by Walter Bright
www.digitalmars.com/d/index.html
Usage:
  dmd files.d ... { -switch }

  files.d        D source files
  -c             do not link
  -d             allow deprecated features
  -g             add symbolic debug info
  -gt            add trace profiling hooks
  -v             verbose
  -O             optimize
  -oobjdir       write .obj files to directory objdir
  -Ipath         where to look for imports
  -Llinkerflag   pass linkerflag to link
  -debug         compile in debug code
  -debug=level   compile in debug code <= level
  -debug=ident   compile in debug code identified by ident
  -inline        do function inlining
  -release	 compile release version
  -unittest      compile in unit tests
  -version=level compile in version code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!-`8``'1E;7`N9%!+`0(4`!0`
M```(`)R,E"XJH;RNH0```!,!```)``````````$`(`"V 9('``!U<V5T96UP
M+F102P$"%``4````"`#DDY0NVXN
A"```9&5M;RYB87102P4&``````4`!0`,`0``BPD`````
`
end
Apr 20 2003