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

Warning C4251 using STL container member in class in DLL

Post 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
{
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;
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 7
Contact:

Post by haffax »

Just a guess: Maybe you're not using multithreaded dll runtime libs? Meaning not /MD or /MDd? If so change it accordingly.
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
x 2
Contact:

Post by pjcast »

Ogre specifically disables that warning, that is how Ogre does it ;)
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
x 3

Post by johnhpus »

Ah, yeah, so it does. Thanks for the speedy response guys.
kitt3n
Kobold
Posts: 33
Joined: Sun Oct 13, 2002 3:40 pm

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

Post 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.
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
x 179
Contact:

Post by jacmoe »

Do a search for "C4251" and "DLL-interface" (or similar).
I saw some workarounds @ MSDN.
/* 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 »

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...
kitt3n
Kobold
Posts: 33
Joined: Sun Oct 13, 2002 3:40 pm

Post 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
Post Reply