Sign in to follow this  

Anyone know how to get rid of the dreaded C4251 warning?

This topic is 4198 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I've done some research on the subject already. I've found some macros exporting all the classes of the containers but it was not working since I have many DLLs. Anyone know how to remove warning C4251: 'std::_List_nod<_Ty,_Alloc>::_Alnod' : class 'std::allocator<_Ty>' needs to have dll-interface to be used by clients of class 'std::_List_nod<_Ty,_Alloc>' aside from disabling the warning?

Share this post


Link to post
Share on other sites
I'm assuming your developing for Win32 here. That warning is telling you that there is a mismatch of exported and non-exported items in a class. Generally something like this is the cause.


class NotExported{
//... whatever
};

class __declspec(dllexport) ExportedClass{

private:
// you are using a non-exported class by value as a member
// in an exported class.
NotExported foo;
};


You can fix the aforementioned code by making foo a pointer or reference to a NotExported instance. Or you could just declare NotExported as __declspec(dllexport) or whatever.

Now this could also happen if one class is declared __declspec(dllimport) and the other is __declspec(dllexport). I would need to see some of your code to help you further.

Share this post


Link to post
Share on other sites
I tried these macros :

#ifndef DllExportH
#define DllExportH

#if defined(_MSC_VER)

#ifdef _DEBUG
# define class_it_base class
#else
# define class_it_base struct
#endif

#define EXPORT_STL_VECTOR(declspec_, T_) template class declspec_ std::allocator<T_ >; template class declspec_ std::vector<T_ >;

#define EXPORT_STL_VECTOR_CONST_ITERATOR(declspec_, T_) class_it_base declspec_ std::_Iterator_base; template class declspec_ std::_Vector_const_iterator<T_,std::allocator<T_ > >;

#define EXPORT_STL_DEQUE(declspec_, T_) template class declspec_ std::allocator<T_ >; template class declspec_ std::allocator<T_* >; template class declspec_ std::deque<T_ >;

#define EXPORT_STL_LIST(declspec_, T_) template class declspec_ std::allocator<T_ >; template class declspec_ std::allocator<std::_List_nod<T_,std::allocator<T_ > >::_Node>; template class declspec_ std::allocator<std::_List_nod<T_,std::allocator<T_ > >::_Node*>; template class declspec_ std::list<T_ >;

#define EXPORT_STL_SET(declspec_, T_) template class declspec_ std::allocator<T_ >; template struct declspec_ std::less<T_ >; template class declspec_ std::allocator<std::_Tree_nod< std::_Tset_traits<T_, std::less<T_ >, std::allocator<T_ >, false> >::_Node>; template class declspec_ std::allocator<std::_Tree_ptr< std::_Tset_traits<T_, std::less<T_ >, std::allocator<T_ >, false> >::_Node*>; template class declspec_ std::set<T_ >;

#define EXPORT_STL_MULTISET(declspec_, T_) template class declspec_ std::allocator<T_ >; template struct declspec_ std::less<T_ >; template class declspec_ std::allocator<std::_Tree_nod< std::_Tset_traits<T_, std::less<T_ >, std::allocator<T_ >, true> >::_Node>; template class declspec_ std::allocator<std::_Tree_ptr< std::_Tset_traits<T_, std::less<T_ >, std::allocator<T_ >, true> >::_Node*>; template class declspec_ std::multiset<T_ >;

#define EXPORT_STL_MAP(declspec_, K_, V_) template struct declspec_ std::less<K_ >; template class declspec_ std::allocator<std::_Tree_nod< std::_Tmap_traits<K_, V_, std::less<K_ >, std::allocator<std::pair<const K_, V_ > >, false> >::_Node>; template class declspec_ std::allocator<std::_Tree_nod< std::_Tmap_traits<K_, V_, std::less<K_ >, std::allocator<std::pair<const K_, V_ > >, false> >::_Node*>; template class declspec_ std::allocator<std::pair<const K_, V_ > >; template class declspec_ std::map<K_, V_ >;

#define EXPORT_STL_MAP_CONST_ITERATOR(declspec_, K_, V_) class_it_base declspec_ std::_Iterator_base; template class declspec_ std::_Tree<std::_Tmap_traits<K_, V_, std::less<K_>, std::allocator<std::pair<const K_, V_ > >, false> >::const_iterator;


#define EXPORT_STL_MULTIMAP(declspec_, K_, V_) template struct declspec_ std::less<K_ >; template class declspec_ std::allocator<std::_Tree_nod< std::_Tmap_traits<K_, V_, std::less<K_ >, std::allocator<std::pair<const K_, V_ > >, true> >::_Node>; template class declspec_ std::allocator<std::_Tree_nod< std::_Tmap_traits<K_, V_, std::less<K_ >, std::allocator<std::pair<const K_, V_ > >, true> >::_Node*>; template class declspec_ std::allocator<std::pair<const K_, V_ > >; template class declspec_ std::multimap<K_, V_ >;

#else

#define EXPORT_STL_VECTOR(declspec_, T_)
#define EXPORT_STL_VECTOR_CONST_ITERATOR(declspec_, T_)
#define EXPORT_STL_DEQUE(declspec_, T_)
#define EXPORT_STL_LIST(declspec_, T_)
#define EXPORT_STL_SET(declspec_, T_)
#define EXPORT_STL_MULTISET(declspec_, T_)
#define EXPORT_STL_MAP(declspec_, K_, V_)
#define EXPORT_STL_MAP_CONST_ITERATOR(declspec_, K_, V_)
#define EXPORT_STL_MULTIMAP(declspec_, K_, V_)

#endif

#endif

And then just

EXPORT(mydeclspec, int, int);
class mydeclspec whatever
{
// boring...
stl::map<int, int> //example...
}

But I had some problems when I did the same thing in another DLL that had a similar definition of the map. It caused linker errors. as described in this article http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html

Share this post


Link to post
Share on other sites

This topic is 4198 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this