Qpid
  1. Qpid
  2. QPID-3478

Windows Visual Studio 2010 warning C4251 'needs to have dll interface' qpid::amqp_0_10::MapCodec::contentType

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.12
    • Fix Version/s: 0.17
    • Component/s: C++ Broker, C++ Client
    • Labels:
      None
    • Environment:

      Windows builds using Visual Studio 2010

      Description

      File cpp/include/qpid/amqp_0_10/Codecs.h has code to the effect of:

      class QPID_COMMON_EXTERN MapCodec

      { public: static const std::string contentType; private: }

      ;

      VS2010 warns that exporting a std::string from a DLL may have unexpected consequences.

      One possible solution is from

      http://www.eggheadcafe.com/software/aspnet/30952961/a-solution-to-warning-c4251--class-needs-to-have-dllinterface.aspx

      2. You can define a wrapper class that has no inline functions and defines all the potentially compiler-generated functions (default ctor, copy ctor, dtor, and assignment operator) and dllexport that.

      Other discussion of this issue:

      http://stackoverflow.com/questions/2132747/warning-c4251-when-building-a-dll-that-exports-a-class-containing-an-atlcstring

        Activity

        Hide
        Chuck Rolke added a comment -

        The actual error message is:

        7>D:\Users\crolke\svn\qpid-vs2010\qpid\cpp\include\qpid/amqp_0_10/Codecs.h(44): 
          warning C4251: 
            'qpid::amqp_0_10::MapCodec::contentType' : 
              class 'std::basic_string<_Elem,_Traits,_Ax>' 
          needs to have dll-interface to be used by clients of class 'qpid::amqp_0_10::MapCodec'
        7>          with
        7>          [
        7>              _Elem=char,
        7>              _Traits=std::char_traits<char>,
        7>              _Ax=std::allocator<char>
        7>          ]
        
        Show
        Chuck Rolke added a comment - The actual error message is: 7>D:\Users\crolke\svn\qpid-vs2010\qpid\cpp\include\qpid/amqp_0_10/Codecs.h(44): warning C4251: 'qpid::amqp_0_10::MapCodec::contentType' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll- interface to be used by clients of class 'qpid::amqp_0_10::MapCodec' 7> with 7> [ 7> _Elem= char , 7> _Traits=std::char_traits< char >, 7> _Ax=std::allocator< char > 7> ]
        Hide
        Chuck Rolke added a comment -

        The fix apparently is to apply the export declarations to individual class members and not to the class in general.

        After some more testing I'll commit this patch.

        Show
        Chuck Rolke added a comment - The fix apparently is to apply the export declarations to individual class members and not to the class in general. After some more testing I'll commit this patch.

          People

          • Assignee:
            Chuck Rolke
            Reporter:
            Chuck Rolke
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development