Linking error when using template class from MFC Extension DLL
-
Have you tried to implement a method int IsEmpty(void) { ... return n; } ??? Seems like the linker can't find the body of this function... Is it a virtual class you are inheriting from? Or is int IsEmpty(void) defined as: in IsEmtpy(void) = 0; ??:confused:
I've implemented all the functions inside the class and it all worked when it was still outside the MFC Extension DLL... There is one thing though, but I don't think it could cause this error: the implementation is done in the .h-file. I would like to try to move the implementation to the .cpp-file, but I never got that working on a template class... :(( Structured programming vs. chaotic mind boggling
-
I've implemented all the functions inside the class and it all worked when it was still outside the MFC Extension DLL... There is one thing though, but I don't think it could cause this error: the implementation is done in the .h-file. I would like to try to move the implementation to the .cpp-file, but I never got that working on a template class... :(( Structured programming vs. chaotic mind boggling
It shouldn't make any difference if the implementation is in the header or in the cpp. The linker doesn't care. It's just a matter of making readable code. Doing all your implementation in the header, just makes the code harder to maintain than necessary.:suss: The key point is that the linker can't find the implementation of that method.
-
I've implemented all the functions inside the class and it all worked when it was still outside the MFC Extension DLL... There is one thing though, but I don't think it could cause this error: the implementation is done in the .h-file. I would like to try to move the implementation to the .cpp-file, but I never got that working on a template class... :(( Structured programming vs. chaotic mind boggling
the implementation is done in the .h-file. So there's no need to mark the template as exported. What happens when you remove AFX_EXT_CLASS? Tomasz Sowinski -- http://www.shooltz.com
-
the implementation is done in the .h-file. So there's no need to mark the template as exported. What happens when you remove AFX_EXT_CLASS? Tomasz Sowinski -- http://www.shooltz.com
I tried it this way as well: template class AFX_EXT_CLASS myClass_Aggregate : public myClass_Object { public: myClass_Aggregate() { ... } ... } but it doesn't make a difference. It just keeps on saying that it can't link to the specific templated instance... For example, when I do this: myClass_Aggregate bla; it says it can't find the implementation of myClass_Aggregate::~myClass_Aggregate(void) The weird thing is that it apparantly CAN find the implementation of the CONSTRUCTOR... I've been looking around a little, but am quite pessimistic about a good outcome for this problem.... Please help me before I get depressed ;) Structured programming vs. chaotic mind boggling
-
I tried it this way as well: template class AFX_EXT_CLASS myClass_Aggregate : public myClass_Object { public: myClass_Aggregate() { ... } ... } but it doesn't make a difference. It just keeps on saying that it can't link to the specific templated instance... For example, when I do this: myClass_Aggregate bla; it says it can't find the implementation of myClass_Aggregate::~myClass_Aggregate(void) The weird thing is that it apparantly CAN find the implementation of the CONSTRUCTOR... I've been looking around a little, but am quite pessimistic about a good outcome for this problem.... Please help me before I get depressed ;) Structured programming vs. chaotic mind boggling
The code posted in last msg still contains AFX_EXT_CLASS. Are you sure you've actually removed AFX_EXT_CLASS? Tomasz Sowinski -- http://www.shooltz.com
-
The code posted in last msg still contains AFX_EXT_CLASS. Are you sure you've actually removed AFX_EXT_CLASS? Tomasz Sowinski -- http://www.shooltz.com
Wait, I'm a little off here, I guess.... I would like to use the template class outside the DLL (i.e. export the template class). But when I remove the AFX_EXT_CLASS from the class definition of myClass_Aggregate, the class won't be exported at all, right? So then I won't be able to use it outside the DLL, right??? Or perhaps I don't understand this very well... Structured programming vs. chaotic mind boggling
-
Wait, I'm a little off here, I guess.... I would like to use the template class outside the DLL (i.e. export the template class). But when I remove the AFX_EXT_CLASS from the class definition of myClass_Aggregate, the class won't be exported at all, right? So then I won't be able to use it outside the DLL, right??? Or perhaps I don't understand this very well... Structured programming vs. chaotic mind boggling
- When you post code, replace > and < with > and <. The template arguments are lost without that - I had to view the HTML source to find out that you're using AFX_EXT_CLASS in template argument declaration. This isn't necessary. 2) Template itself doesn't produce any code, so there's no need to export it. All information is in .h file, as you have already mentioned. 3) Your template derives from non-template myClass_object. This class must be exported. Tomasz Sowinski -- http://www.shooltz.com
-
- When you post code, replace > and < with > and <. The template arguments are lost without that - I had to view the HTML source to find out that you're using AFX_EXT_CLASS in template argument declaration. This isn't necessary. 2) Template itself doesn't produce any code, so there's no need to export it. All information is in .h file, as you have already mentioned. 3) Your template derives from non-template myClass_object. This class must be exported. Tomasz Sowinski -- http://www.shooltz.com
>1) When you post code, replace > and < with > and <. The template arguments are >lost without that - I had to view the HTML source to find out that you're using >AFX_EXT_CLASS in template argument declaration. This isn't necessary. Whoops. Sorry. Never thought of that. Pretty stupid of me. >2) Template itself doesn't produce any code, so there's no need to export it. All >information is in .h file, as you have already mentioned. Right. >3) Your template derives from non-template myClass_object. This class must be exported. It was already exported, but it didn't seem to help. My theory about the whole messy situation is that template-classes can't be exported. I read somewhere else over at CodeGuru.com that the template construction is a compile-time trick and since the extension dll has already been compiled, it probably can't use any template classes. I've solved the problem by repeating the code of the template class inside the .h-file that I distribute together with the .lib en .dll file. That way it is compiled both in the extension DLL and in the application that uses the dll. Not an ideal solution, but it works for now. If anyone has valuable input about this situation, I'd love to hear it! Thanks for all your help so far. Dave Structured programming vs. chaotic mind boggling
-
>1) When you post code, replace > and < with > and <. The template arguments are >lost without that - I had to view the HTML source to find out that you're using >AFX_EXT_CLASS in template argument declaration. This isn't necessary. Whoops. Sorry. Never thought of that. Pretty stupid of me. >2) Template itself doesn't produce any code, so there's no need to export it. All >information is in .h file, as you have already mentioned. Right. >3) Your template derives from non-template myClass_object. This class must be exported. It was already exported, but it didn't seem to help. My theory about the whole messy situation is that template-classes can't be exported. I read somewhere else over at CodeGuru.com that the template construction is a compile-time trick and since the extension dll has already been compiled, it probably can't use any template classes. I've solved the problem by repeating the code of the template class inside the .h-file that I distribute together with the .lib en .dll file. That way it is compiled both in the extension DLL and in the application that uses the dll. Not an ideal solution, but it works for now. If anyone has valuable input about this situation, I'd love to hear it! Thanks for all your help so far. Dave Structured programming vs. chaotic mind boggling
What exactly do you want to achieve? Do you want users of your DLL to pass types unknown inside the DLL as template arguments?
myClass_aggregate<classFromSomeOtherExeOrDll> x;
In this case, you need to distribute .h file. Template construction occurs at compile time - this is no surprise, because template itself is not a complete type. Compiler needs to know what are the template arguments. Or -- maybe you just want to export a few specializations of your template, like this:
myClass_aggregate<classFromThisExtenstionDll> y;
myClass_aggregate<anotherClassFromThisExtenstionDll> z;In this scenario you have one more option - you can explicitly instantiate the type. See "Explicit Instantiation" in C++ Language Reference included in VC++ help and KB article Q168958 for more details. Tomasz Sowinski -- http://www.shooltz.com
-
What exactly do you want to achieve? Do you want users of your DLL to pass types unknown inside the DLL as template arguments?
myClass_aggregate<classFromSomeOtherExeOrDll> x;
In this case, you need to distribute .h file. Template construction occurs at compile time - this is no surprise, because template itself is not a complete type. Compiler needs to know what are the template arguments. Or -- maybe you just want to export a few specializations of your template, like this:
myClass_aggregate<classFromThisExtenstionDll> y;
myClass_aggregate<anotherClassFromThisExtenstionDll> z;In this scenario you have one more option - you can explicitly instantiate the type. See "Explicit Instantiation" in C++ Language Reference included in VC++ help and KB article Q168958 for more details. Tomasz Sowinski -- http://www.shooltz.com
Actually I wanted what you first described... But reflecting on it, I only want to use the aggregate for subtypes of the myClass_Object class, so that may bring me to your second case... Is it so, that when I explicitly instatiate a supertype, that it will also work for all subtypes of that supertype?? In that case I am probably able to solve it the elegant way, anyway! Thanx a lot! Structured programming vs. chaotic mind boggling