> In native mode I can export class template from a DLL this way:
> template <typename T> class TSuperType
[quoted text clipped - 6 lines]
>
> template class __declspec (dllexport) TSuperType<int>;
this will generate a compiler warning (C4661) with VS2005 because there is
no suitable definition for doSomething. i.e. there is no implementation of
that function, only a declaration. I assume that you implement that function
where you typed '...'?
I.e.
template <typename T> T TSuperType<T>::doSomething()
{
return T(); //or do something useful here
}
template class __declspec (dllexport) TSuperType<int>;
> And I can import it this way in another module:
> template class __declspec (dllimport) TSuperType<int>;
did you add the lib file of your dll to the linker input of your
application? otherwise the linker will not find the implementation of the
methods in your template and you will get those errors when building the
application.
Once the linker input is OK, and with all the methods defined before the
dllexport, the code compiles and links without a problem with /clr set.

Signature
Kind regards,
Bruno van Dooren
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"
Vyacheslav Lanovets - 16 Apr 2006 15:38 GMT
Yes, I implemented doSomething() to "return T();" just before
__declspec(dllexport) directive.
#include "templ.h"
template <typename T>
T TSuperType<T>::doSomething()
{
return T();
}
template class __declspec (dllexport) TSuperType<int>;
I have both projects in one solution and I just set dependencies between
them.
It compiles, links and works perfectly without /clr switch.
But it complains with /clr switch.
>> In native mode I can export class template from a DLL this way:
>> template <typename T> class TSuperType
[quoted text clipped - 27 lines]
> Once the linker input is OK, and with all the methods defined before the
> dllexport, the code compiles and links without a problem with /clr set.
Bruno van Dooren - 16 Apr 2006 16:10 GMT
> I have both projects in one solution and I just set dependencies between
> them.
> It compiles, links and works perfectly without /clr switch.
> But it complains with /clr switch.
I did the same, but I also had to explicitly specify the lib file of the dll
as an additional linker input.
Doing that makes it work. not doing that results in the linker errors you
posted.
To be honest I don't know if it is a bug or a feature...

Signature
Kind regards,
Bruno van Dooren
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"
Vyacheslav Lanovets - 16 Apr 2006 16:47 GMT
Thank you for you help.
I think it's a bug.
http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?FeedbackId=4400e
b66-eefb-4209-8ff1-e533c026cc3f
>> I have both projects in one solution and I just set dependencies between
>> them.
[quoted text clipped - 6 lines]
> posted.
> To be honest I don't know if it is a bug or a feature...
Bruno van Dooren - 17 Apr 2006 14:24 GMT
> Thank you for you help.
> I think it's a bug.
> http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?FeedbackId=4400e
b66-eefb-4209-8ff1-e533c026cc3f
I did some additional testing, and I think I know why it is like this.
If your dll is unmanaged, it is reasonable to expect that it would contain
exports.
if another project depends upon it, it is therefore reasonable to feed the
lib file into the linker command for the application. That is why 'Link
library dependencies' is set by default.
if you specify the /clr switch for the dll, the assumption that it will
contain unmanaged exports is no longer valid.
it could just as well be a classlib. in that case (no native exports) there
will be no lib file because there are no import directives to generate. If
there is no lib file, the build of your app would fail since it would expect
it to be there.
So on one hand, it is not unreasonable that the lib file is not
automatically fed into the linker command of the app (since the dependency
could be a managed one instead of an unmanaged one). On the other hand, the
flag 'Link library dependencies' is still set to yes, so you would expect it
to do so, regardless of the build options of the dll.
It seems that VS ignores the 'Link library dependencies' option for mixed
mode dlls
If that is so they should at least have mentioned it in the documentation
for 'Link library dependencies'
Anyway I have validated it, but only rated it as an annoyance because VS
errs on the safe side and it is trivial to work around

Signature
Kind regards,
Bruno van Dooren
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"