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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Q 
MS4"*%C 9B_LZ?M+M ]^E?SA]QTM$.;4O >? 8G8)AD%Y#4[-M3:>`Z 61.`V
M[33LQKO[+'QO2UV+,'R(Y7KDTG#PI! N"=>T]F4DRTA2\%\P/03X)M4FI6WU
M5KP8$]=_1XH'$ FR>"^K%"!>N.*P-G=GS,:ILLEE1>+G/, W!Q+B4E.L0+1"
M--I85\WX<]ZN];.F#>'(=H&D'$*D,%ATVX:3H_9B?$95'H&\99^!YK2)<RWM
M^_AVA"M2,L'+&.Z[&U!+`0(4`!0````(`"*4E"YP:J'A=P4``&,4```*````
M``````$`(`"V 0````!R97!O<G0N='AT4$L!`A0`%````` `%HJ4+JC[FTAR
M````X`````4``````````0` `+:!GP4``&5R<BYD4$L!`A0`%````` `")"4
M+G]7[E`Z`0``N (```8``````````0` `+:!-`8``'1E;7`N9%!+`0(4`!0`
M```(`)R,E"XJH;RNH0```!,!```)``````````$`(`"V 9('``!U<V5T96UP
M+F102P$"%``4````"`#DDY0NVXN;8 L!``#[! ``"``````````!`"``_X%:
A"```9&5M;RYB87102P4&``````4`!0`,`0``BPD`````
`
end
Apr 20 2003