Warning C4251 using STL container member in class in DLL

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am

Warning C4251 using STL container member in class in DLL

Post by johnhpus » Thu Jun 22, 2006 5:00 pm

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
{
public:
	IEventReceiver();
	virtual ~IEventReceiver();

private:
	IEventReceiver( IEventReceiver const& );

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

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

private:
        // 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.

Edit:
Here's the typdef for EventList

Code: Select all

typedef std::list<IEvent*> EventList;
0 x

User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
Contact:

Post by haffax » Thu Jun 22, 2006 5:09 pm

Just a guess: Maybe you're not using multithreaded dll runtime libs? Meaning not /MD or /MDd? If so change it accordingly.
0 x
team-pantheon programmer
creators of Rastullahs Lockenpracht

User avatar
pjcast
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2543
Joined: Fri Oct 24, 2003 2:53 am
Location: San Diego, Ca
Contact:

Post by pjcast » Thu Jun 22, 2006 5:18 pm

Ogre specifically disables that warning, that is how Ogre does it ;)
0 x
Have a question about Input? Video? WGE? Come on over... http://www.wreckedgames.com/forum/

User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am

Post by johnhpus » Thu Jun 22, 2006 5:29 pm

Ah, yeah, so it does. Thanks for the speedy response guys.
0 x

kitt3n
Kobold
Posts: 33
Joined: Sun Oct 13, 2002 3:40 pm

Post by kitt3n » Wed Jun 28, 2006 9:18 pm

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
{
private:
std::vector <char> buf; //< Error 1744 on this line
}
0 x

User avatar
pjcast
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2543
Joined: Fri Oct 24, 2003 2:53 am
Location: San Diego, Ca
Contact:

Post by pjcast » Wed Jun 28, 2006 11:33 pm

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.
0 x
Have a question about Input? Video? WGE? Come on over... http://www.wreckedgames.com/forum/

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Post by jacmoe » Thu Jun 29, 2006 12:05 am

Do a search for "C4251" and "DLL-interface" (or similar).
I saw some workarounds @ MSDN.
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

Rackle
Gnome
Posts: 375
Joined: Sat Jul 16, 2005 1:42 am
Location: Montreal

Post by Rackle » Thu Jun 29, 2006 12:55 am

http://www.unknownroad.com/rtfm/VisualS ... 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...
0 x

kitt3n
Kobold
Posts: 33
Joined: Sun Oct 13, 2002 3:40 pm

Post by kitt3n » Wed Jul 12, 2006 11:28 pm

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
0 x

Post Reply