re: c++ template instanciation and dlls on win32

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



c++ template instanciation and dlls on win32

    * From: Mathieu Lacage <Mathieu dot Lacage at sophia dot inria dot
fr>
    * To: gcc-help at gcc dot gnu dot org
    * Date: Sat, 30 Jun 2007 19:30:45 +0200
    * Subject: c++ template instanciation and dlls on win32


> Here is my sample code: 
> http://www-sop.inria.fr/dream/personnel/Mathieu.Lacage/tmp.tar.gz


This is what I would do:

Exolicitly, force instantiation of your template instance in dll:

diff -c3p tmp/test.cc tmp0/test.cc
*** tmp/test.cc	Sat Jun 30 21:30:22 2007
--- tmp0/test.cc	Sun Jul  1 15:49:20 2007
***************
*** 1,5 ****
--- 1,8 ----
  #include "test.h"
  
+ // instantiate
+ template class Test <0>;
+ 
  void Function (void)
  {
    Test<0>::Exec ();



Explictly mark the reference to your imported instantation as imported.

*** tmp/main.cc	Sat Jun 30 21:30:14 2007
--- tmp0/main.cc	Sun Jul  1 15:54:16 2007
***************
*** 1,5 ****
--- 1,8 ----
  #include "test.h"
  
+ // Import rather than instantiate
+ extern template class __declspec (dllimport) Test <0>;
+ 
  void Function (void);
  
  int main (int argc, char *argv[])



In addition, on windows the ".so" extension is unusual.  The linker will
have less difficulty if you
use the windows ".dll" extension

*** tmp/Makefile	Sat Jun 30 21:33:00 2007
--- tmp0/Makefile	Sun Jul  1 15:42:45 2007
***************
*** 1,7 ****
! all: libtest.so main
  
! libtest.so: test.o
  	g++ -shared -o $@ $^
  
  main: main.o 
! 	g++ -L. -ltest -o $@ $^
--- 1,7 ----
! all: libtest.dll main
  
! libtest.dll: test.o
  	g++ -shared -o $@ $^
  
  main: main.o 
! 	g++ -L. -ltest -o $@ $^
  


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux