This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
re: c++ template instanciation and dlls on win32
- From: Danny Smith <dannysmith at clear dot net dot nz>
- To: GCC-help at gcc dot gnu dot org
- Cc: Mathieu dot Lacage at sophia dot inria dot fr
- Date: Sun, 01 Jul 2007 22:30:56 +1200
- Subject: re: c++ template instanciation and dlls on win32
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 $@ $^