template STL and DLL

W

whatazor

Hi all,
I've a std::set defined inside a class that must be exported/imported.

I've use this macro:

#define EXPORT_STL_SET( dllmacro, settype ) \
template class dllmacro std::allocator< settype >; \
template struct dllmacro std::less< settype >; \
template class dllmacro std::allocator< \
std::_Tree_nod<std::_Tset_traits<settype,std::less<settype>, \
std::allocator<settype>,false> > >; \
template class dllmacro std::allocator< \
std::_Tree_ptr<std::_Tset_traits<settype,std::less<settype>, \
std::allocator<settype>,false> > >; \
template class dllmacro std::_Tree_ptr< \
std::_Tset_traits<settype,std::less<settype>, \
std::allocator<settype>,false> >; \
template class dllmacro std::_Tree_nod< \
std::_Tset_traits<settype,std::less<settype>, \
std::allocator<settype>,false> >; \
template class dllmacro std::_Tree_val< \
std::_Tset_traits<settype,std::less<settype>, \
std::allocator<settype>,false> >; \
template class dllmacro std::set< settype, std::less< settype >, \
std::allocator< settype > >;

find here:
http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html

but it gives me other 4251 warning like these:

C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xtree(65) : warning C4251: 'std::_Tree_nod<_Traits>::_Alnod' : class
'std::allocator<_Ty>' needs to have dll-interface to be used by
clients of class 'std::_Tree_nod<_Traits>'
with
[

_Traits=std::_Tset_traits<myClass,std::less<myClass>,std::allocator<myClass>,false>
]
and
[

_Ty=std::_Tree_nod<std::_Tset_traits<myClass,std::less<myClass>,std::allocator<myClass>,false>>::_Node
]
and
[

_Traits=std::_Tset_traits<myClass,std::less<myClass>,std::allocator<myClass>,false>
]
c:\cvsMAF\DLLTEST_openMAF22_ITK\IO\testClass.h(160) : see
reference to class template instantiation 'std::_Tree_ptr<_Traits>'
being compiled
with
[

_Traits=std::_Tset_traits<myClass,std::less<myClass>,std::allocator<myClass>,false>
]


I use Visual Studio .NET 2003. How can get rid of all these warning?
 
S

Sheng Jiang[MVP]

Expoer accessor methods instead of the template class. See Knowledge Base
article 172396
PRB: Access Violation When Accessing STL Object in DLL

--
Sheng Jiang
Microsoft MVP in VC++
whatazor said:
Hi all,
I've a std::set defined inside a class that must be exported/imported.

I've use this macro:

#define EXPORT_STL_SET( dllmacro, settype ) \
template class dllmacro std::allocator< settype >; \
template struct dllmacro std::less< settype >; \
template class dllmacro std::allocator< \
std::_Tree_nod<std::_Tset_traits<settype,std::less<settype>, \
std::allocator<settype>,false> > >; \
template class dllmacro std::allocator< \
std::_Tree_ptr<std::_Tset_traits<settype,std::less<settype>, \
std::allocator<settype>,false> > >; \
template class dllmacro std::_Tree_ptr< \
std::_Tset_traits<settype,std::less<settype>, \
std::allocator<settype>,false> >; \
template class dllmacro std::_Tree_nod< \
std::_Tset_traits<settype,std::less<settype>, \
std::allocator<settype>,false> >; \
template class dllmacro std::_Tree_val< \
std::_Tset_traits<settype,std::less<settype>, \
std::allocator<settype>,false> >; \
template class dllmacro std::set< settype, std::less< settype >, \
std::allocator< settype > >;

find here:
http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html

but it gives me other 4251 warning like these:

C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xtree(65) : warning C4251: 'std::_Tree_nod<_Traits>::_Alnod' : class
'std::allocator<_Ty>' needs to have dll-interface to be used by
clients of class 'std::_Tree_nod<_Traits>'
with
[
_Traits=std::_Tset_traits said:
_Ty=std::_Tree_nod said:
_Traits=std::_Tset_traits said:
]
c:\cvsMAF\DLLTEST_openMAF22_ITK\IO\testClass.h(160) : see
reference to class template instantiation 'std::_Tree_ptr<_Traits>'
being compiled
with
[
_Traits=std::_Tset_traits said:
]


I use Visual Studio .NET 2003. How can get rid of all these warning?
 

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

Top