473,409 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Template instantiation! Linker Problem

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!

Jul 19 '05 #1
1 2073

"K.S." <sc*****@tuwien.ac.at> wrote in message
news:3f***********************@newsreader02.highwa y.telekom.at...
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-lit....html#faq-34.1
2

HTH,
-Mike
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dave | last post by:
Hello all, Consider this function template definition: template<typename T> void foo(T) {} If foo is never called, this template will never be instantiated. Now consider this explicit...
7
by: Andrew Ward | last post by:
Hi All, Considering the following code: struct A; struct B { std::list<A> l; };
4
by: Dave | last post by:
Hello all, Consider this template: template <typename T> void foo(T bar) {...} Here are three ways to instantiate this: 1.
5
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func(); }; template<class T, unsigned N>
7
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type ...
2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
3
by: sks | last post by:
Hello all Is the usage of extern keyword valid for telling the compiler to NOT instantiate a template and to link it from an another binary? For example: Suppose module A's binary contains a...
8
by: mattias.nissler | last post by:
Hi! Here is a problem I ran into at work. The following example doesn't compile on gcc-4.1: struct cons_end {}; template<typename U,typename Vstruct cons { U elem; V tail;
2
by: Juha Nieminen | last post by:
Paavo Helde wrote: So which compiler is correct, gcc (which only requires bar() to be declared at the point of insantiation of foo()) or comeau? What happens if you just move the bar()...
4
by: Pallav singh | last post by:
Hi All, i am getting error during explicit function Instantiation for a class Template if i do explicit Instantiation of class it work and all function symbol i get in object file But if i...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.