[interprocess] warning C4251: need dll-interface
I've defined a class to use within shared memory, and I've decorated it with a Windows _declspec(export) to expose it from a DLL. When I compiled with VC 2008, I got this warning:
Warning C4251: class 'boost::interprocess::vector
Brent Arias wrote:
Does this also apply to boost.interprocess? Is it really safe to ignore this warning and continue to use the interprocess code from within a DLL?
It's not Interprocess fault. It's a widely known issue with templates and linkage. See http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html and Microsoft's own http://support.microsoft.com/kb/168958/en-us to see what you want to do with the class and what you can do to achieve it.
Brent Arias
Best, Ion
On Wed, Apr 8, 2009 at 11:28 PM, Brent Arias
I've defined a class to use within shared memory, and I've decorated it with a Windows _declspec(export) to expose it from a DLL. When I compiled with VC 2008, I got this warning:
Warning C4251: class 'boost::interprocess::vector
' needs to have dll-interface to be used by clients of 'MyClass' I searched boost user archives for any discussion of this, and in the context of boost.signals I've seen someone comment to simply disable the warning with:
#pragma warning (disable: 4251) Std::list
talkers; #pragma warning (default: 4151) Does this also apply to boost.interprocess? Is it really safe to ignore this warning and continue to use the interprocess code from within a DLL?
Brent Arias
Brent - this warning applies because you've decorated the whole class with _declspec(dllexport). If you only decorate the public (and protected, I guess, taking inheritance into account) methods and data with _declspec(dllexport), those warnings will go away (unless they were originally being reported for public or protected data, of course). As an example: class A { public: _declspec(dllexport) A(); _declspec(dllexport) ~A(); _declspec(dllexport) A(const A&); _declspec(dllexport) A& operator=(const A&); _declspec(dllexport) size_t Count(std::list<int> const); private: std::list<int> l; }; Visual C++ is happy with that, but if I move the declspec onto the class, Visual C++ complains about the data member. Stuart Dootson
On Wed, Apr 8, 2009 at 11:28 PM, Brent Arias
wrote: I've defined a class to use within shared memory, and I've decorated it with a Windows _declspec(export) to expose it from a DLL. When I compiled with VC 2008, I got this warning:
Warning C4251: class 'boost::interprocess::vector
' needs to have dll-interface to be used by clients of 'MyClass'
There is an explanation of this problem at http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html. The short version is that it is nearly always ok to ignore the warning but there is real underlying risk of strange errors if you link libraries compiled with different compilers or compiler options.
participants (4)
-
Brent Arias
-
Ion Gaztañaga
-
Peter Bartlett
-
Stuart Dootson