Boost logo

Boost Users :

Subject: Re: [Boost-users] [interprocess] warning C4251: need dll-interface
From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2009-04-09 05:37:16


On Wed, Apr 8, 2009 at 11:28 PM, Brent Arias <Brent.Arias_at_[hidden]> 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<T,A>' 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<OtherClass*> 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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net