Exporting STL containers (specifically std::map) from DLL? 
Author Message
 Exporting STL containers (specifically std::map) from DLL?

Hello,

I recently moved to using VC7 (7.0.9466)  from VC6 since I had some classes
that were derived from and/or contained STL containers other than vector<>
that I need to export from a DLL.  Since VC6 didn't support exporting those
classes, I tried VC7, which seems to work.  I still get lots of warnings
during my compiles and I have some unanswered questions.

I'm trying to use the following:
class __declspec(dllexport) CBase {...};

template <class K, class D> class __declspec(dllexport) CListBase : public
CBase, public std::map<K, D>  {
  iterator Find(const K&key);
  const_iterator Find(const K&key) const;

Quote:
};

class __declspec(dllexport) CList1 : public CListBase<mykey, mydata> {...};

(NOTE: class mydata has operator<(const class mydata) and operator==(const
class mydata).)

1. Do I have to explicitly instantiate template specializations in my DLL?

2. If I just export std::map<mykey,mydata>, I get the C4251 warnings

'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>::comp' : struct
'std::less<_Ty>', 'std::_Tree_nod<_Traits>::_Alnod' : class
'std::allocator<_Ty>'
and
'std::_Tree_ptr<_Traits>::_Alptr' : class 'std::allocator<_Ty>'

Do I need to worry about these warnings, and if so how do I get rid of them
(without #pragma warning ( disable : 4251 ))?

3. It seems whether I instantiate the specializations or not,  when I look
at the resultant DLL with depends.exe, the appropriate specializations seem
to already be in the DLL.

The latest MSDN didn't seem to have any updated information on exporting STL
containers.

Thanks in advance for any help.

Al Dorundo



Fri, 19 Nov 2004 22:09:47 GMT  
 Exporting STL containers (specifically std::map) from DLL?
It's generally a bad idea to derive from STL containers; they don't have a
virtual destructor and could leak memory, at best.

If you really need to build a newer class on top (and doing it only to make
member functions out of free functions seems like a rather dubious gain),
why not do it in terms of containment?

Quote:
> Hello,

> I recently moved to using VC7 (7.0.9466)  from VC6 since I had some
classes
> that were derived from and/or contained STL containers other than vector<>
> that I need to export from a DLL.  Since VC6 didn't support exporting
those
> classes, I tried VC7, which seems to work.  I still get lots of warnings
> during my compiles and I have some unanswered questions.

> I'm trying to use the following:
> class __declspec(dllexport) CBase {...};

> template <class K, class D> class __declspec(dllexport) CListBase : public
> CBase, public std::map<K, D>  {
>   iterator Find(const K&key);
>   const_iterator Find(const K&key) const;
> };

> class __declspec(dllexport) CList1 : public CListBase<mykey, mydata>
{...};

> (NOTE: class mydata has operator<(const class mydata) and operator==(const
> class mydata).)

> 1. Do I have to explicitly instantiate template specializations in my DLL?

> 2. If I just export std::map<mykey,mydata>, I get the C4251 warnings

> 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>::comp' : struct
> 'std::less<_Ty>', 'std::_Tree_nod<_Traits>::_Alnod' : class
> 'std::allocator<_Ty>'
> and
> 'std::_Tree_ptr<_Traits>::_Alptr' : class 'std::allocator<_Ty>'

> Do I need to worry about these warnings, and if so how do I get rid of
them
> (without #pragma warning ( disable : 4251 ))?

> 3. It seems whether I instantiate the specializations or not,  when I look
> at the resultant DLL with depends.exe, the appropriate specializations
seem
> to already be in the DLL.

> The latest MSDN didn't seem to have any updated information on exporting
STL
> containers.

> Thanks in advance for any help.

> Al Dorundo




Mon, 22 Nov 2004 22:01:24 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Exporting STL containers in an extension DLL

2. Problem with STL Maps in Release Builds exported from DLL's

3. Export STL map from a lib/dll

4. export classes using std namespace (ex std::vector) in a DLL

5. Passing std::set and std::map objects between 2 dlls

6. OLECHAR's in an STL map container?

7. (vc5.0) STL map container is a pig...?

8. STL, std::allocator and memory mapped files

9. URGENT: STL std::map<ULONG, CEvent>

10. problem using std::string in exported class to be puit in a DLL

11. Need help exporting std::string from dll

12. How to export a std::string from a DLL

 

 
Powered by phpBB® Forum Software