Template instantiation! Linker Problem

M

Mike Wahler

K.S. said:
If have template lets call it
template class MyTemplate<class T>
and the files MyTemplate.cc & MyTemplate.hh
In
/* MyTemplate.cc */

// definitions ....

template class MyTemplate<someType>; // works fine
/* end */

The Problem is when build a library out of this
lets call it MyLib.so and link this to another
project. I want define new specializations,
because of a type defined in this new
compile unit!

/* NewProject.cc */
template class MyTemplate<InNewProjectDefinedType>;
...
MyTemplate<InNewProjectDefinedType> someVar;
...
/* end */

I use gnu gcc-3.2.3! And everything compiles fine,
but when I try to link everything I get the error
undefined MyTemplate::constructors and methods

Someone out there who has some experience with
templates and can help me! I know there are some
tricks with #pragma interface/implementation
and some compiler flags -frepo,
fno-implicit-templates but don't really know
how to use them!

If this issue has already come up please forgive,
I'm new to the newsgroup.

PS: yes this isn't the actual code, no I cannot
disclose it(maybe some parts, per mail only)!
Please no answers from newbs trying to
show off!

See the FAQ:
http://www.parashift.com/c++-faq-lite/containers-and-templates.html#faq-34.1
2

HTH,
-Mike
 
K

K.S.

If have template lets call it
template class MyTemplate<class T>
and the files MyTemplate.cc & MyTemplate.hh
In
/* MyTemplate.cc */

// definitions ....

template class MyTemplate<someType>; // works fine
/* end */

The Problem is when build a library out of this
lets call it MyLib.so and link this to another
project. I want define new specializations,
because of a type defined in this new
compile unit!

/* NewProject.cc */
template class MyTemplate<InNewProjectDefinedType>;
....
MyTemplate<InNewProjectDefinedType> someVar;
....
/* end */

I use gnu gcc-3.2.3! And everything compiles fine,
but when I try to link everything I get the error
undefined MyTemplate::constructors and methods

Someone out there who has some experience with
templates and can help me! I know there are some
tricks with #pragma interface/implementation
and some compiler flags -frepo,
fno-implicit-templates but don't really know
how to use them!

If this issue has already come up please forgive,
I'm new to the newsgroup.

PS: yes this isn't the actual code, no I cannot
disclose it(maybe some parts, per mail only)!
Please no answers from newbs trying to
show off!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top