Page 1 of 1

Warning C4251 using STL container member in class in DLL

Posted: Thu Jun 22, 2006 5:00 pm
by johnhpus
I'm trying to export a class for a dll that has a std::list member variable, but the compiler gives me this warning:

Code: Select all

(32) : warning C4251: 'IEventReceiver::mPendingEvents' : class 'std::list<_Ty>' needs to have dll-interface to be used by clients of class 'IEventReceiver'
The code looks like this:

Code: Select all

class EGExport IEventReceiver
	virtual ~IEventReceiver();

	IEventReceiver( IEventReceiver const& );

	void receiveEvent( IEvent *event );
	virtual void handleEvent( IEvent *event ) = 0;
	void handleAllEvents();

	virtual void subscribeToEvents() = 0;
	void unsubscribeFromAllEvents();

        // compiler is complaining about the line below
	EventList mPendingEvents;	
I've looked through Ogre's code and though I can see that Ogre is successfully doing this, I can't figure out how.

Any help would be much appreciated.

Here's the typdef for EventList

Code: Select all

typedef std::list<IEvent*> EventList;

Posted: Thu Jun 22, 2006 5:09 pm
by haffax
Just a guess: Maybe you're not using multithreaded dll runtime libs? Meaning not /MD or /MDd? If so change it accordingly.

Posted: Thu Jun 22, 2006 5:18 pm
by pjcast
Ogre specifically disables that warning, that is how Ogre does it ;)

Posted: Thu Jun 22, 2006 5:29 pm
by johnhpus
Ah, yeah, so it does. Thanks for the speedy response guys.

Posted: Wed Jun 28, 2006 9:18 pm
by kitt3n
I'm using the intel-compiler (just wanted to play around a bit with it)
and I think having the same problem (different errorcode though
because of the compiler)....
Although the intel-compilers marks it as an error, not a warning...

Does anyone know if I can do something simular to 'make the
problem go away' - or is there a 'correct' way to solve it?


error #1744: field of class type without a DLL interface used in
a class with a DLL interface

class _MyExport Derived : public Base
std::vector <char> buf; //< Error 1744 on this line

Posted: Wed Jun 28, 2006 11:33 pm
by pjcast
You should do some google searching, I have seen a workaround, where the template can be exported too. I suggest you search using the Windows warning number, you will find more specific hits on the matter. However, the workaround was not pretty, and only mostly worked IIRC.

Posted: Thu Jun 29, 2006 12:05 am
by jacmoe
Do a search for "C4251" and "DLL-interface" (or similar).
I saw some workarounds @ MSDN.

Posted: Thu Jun 29, 2006 12:55 am
by Rackle ... C4251.html

This is what you're looking for:

Code: Select all

struct SMessage{
	std::string code;
	std::vector<SMessageDesc> messages;
// The following lines are required to properly export std::vector from a DLL
template class DLL_EXPORT std::allocator<SMessage>;
template class DLL_EXPORT std::vector<SMessage, std::allocator<SMessage> >;
std::vector<SMessage> mMessages;
If only I could get back that night spent searching for this answer...

Posted: Wed Jul 12, 2006 11:28 pm
by kitt3n
Thanks guys!

Going to try that out tomorrow!

as a sidenote, I did google on it with variations on the (intel) error message,
but it didn't show up with any solutions - didn't cross my mind
to google on the microsoft message (because in vc7 it's working) lol