txTask.o: In function `TxMgrTask::TxMgrTask(RWCString, int,
int)':
txTask.C:(.text+0x6b37): undefined reference to `DDMSDBAgentManager<DDMSUsn, unsigned long>::DDMSDBAgentManager(TxMgrTask*, int, int)'
txTask.o: In function `TxMgrTask::TxMgrTask(RWCString, int, int)':
txTask.C:(.text+0x7e47): undefined reference to `DDMSDBAgentManager<DDMSUsn, unsigned long>::DDMSDBAgentManager(TxMgrTask*, int, int)'
collect2: ld returned 1 exit status
txTask.C:(.text+0x6b37): undefined reference to `DDMSDBAgentManager<DDMSUsn, unsigned long>::DDMSDBAgentManager(TxMgrTask*, int, int)'
txTask.o: In function `TxMgrTask::TxMgrTask(RWCString, int, int)':
txTask.C:(.text+0x7e47): undefined reference to `DDMSDBAgentManager<DDMSUsn, unsigned long>::DDMSDBAgentManager(TxMgrTask*, int, int)'
collect2: ld returned 1 exit status
I try to compile using g++ in linux .I get
these errors.
I have already saw the solution what you
have mentioned for a query in gcc.org.
I didnt get it correctly.Could you please
make me understand?
I would appreciate if you could help me with
some examples.
As far as i inderstand if we try to
instantiate a template class apart from the file where the template clsass has
been defined there is a issue.
You have told one workaround.But i didnt get
it.
Suppose if i include first.h in main.c
and try to instantiate the template i get errors.Where should i write as per
your suggestion?
first.h
---------
template<class T>
> class first {
> private:
> ...
> public:
> first()
> ~first()
> };
> template<class T>
> first<T>::first()
> {
> ...
> }
> class first {
> private:
> ...
> public:
> first()
> ~first()
> };
> template<class T>
> first<T>::first()
> {
> ...
> }
main.c
-------------
#include<first.h>
class main
{
main()
{
obj = new template(int);
}
};
int main()
{
main *ptr = new main();
}
Regards
Mani.1
>>>>> Orn E Hansen <[EMAIL PROTECTED]> writes:
> The program compiles without errors, but when the linker is to link the
> object files, it is persistent that the reference to 'something' within
> the main program is undefined to 'ancestor<...>'. Every reference to
> the object 'ancestor<int>' is reported as undefined in the program.
> Does anyone have a clue as to why this occurs, and if there is a cure
> to this?
I think you have come across a well known bug/limitation in g++ 2.7.x
Basically g++ fails to instantiate templates properly (or at all) if
the definition is in a separate file to the instantiation; so the
linker reports "undefined references".
The work around is to explicitly instantiate the template with
whatever classes you are are going to use in the same file as the
definition.
So in your example:
> template<class T>
> class ancestor {
> private:
> ...
> public:
> ancestor()
> ~ancestor()
> };
> template<class T>
> ancestor<T>::ancestor()
> {
> ...
> }
add this to the end of the file:
template class ancestor<int>;
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com |