Hi Mark,
Those warnings are not limited to the EPICS V4 code. They occur even for very simple C++ classes that include STL containers. For example this is the definition of the
NDAttribute class in ADCore:
class epicsShareClass NDAttribute {
public:
/* Methods */
NDAttribute(const char *pName, const char *pDescription,
NDAttrSource_t sourceType, const char *pSource, NDAttrDataType_t dataType, void *pValue);
NDAttribute(NDAttribute& attribute);
static const char *attrSourceString(NDAttrSource_t type);
virtual ~NDAttribute();
virtual NDAttribute* copy(NDAttribute *pAttribute);
virtual const char *getName();
virtual const char *getDescription();
virtual const char *getSource();
virtual const char *getSourceInfo(NDAttrSource_t *pSourceType);
virtual NDAttrDataType_t getDataType();
virtual int getValueInfo(NDAttrDataType_t *pDataType, size_t *pDataSize);
virtual int getValue(NDAttrDataType_t dataType, void *pValue, size_t dataSize=0);
virtual int getValue(std::string& value);
virtual int setDataType(NDAttrDataType_t dataType);
virtual int setValue(const void *pValue);
virtual int setValue(const std::string&);
virtual int updateValue();
virtual int report(FILE *fp, int details);
friend class NDArray;
friend class NDAttributeList;
private:
template <typename epicsType> int getValueT(void *pValue, size_t dataSize);
std::string name_; /**< Name string */
std::string description_; /**< Description string */
NDAttrDataType_t dataType_; /**< Data type of attribute */
NDAttrValue value_; /**< Value of attribute except for strings */
std::string string_; /**< Value of attribute for strings */
std::string source_; /**< Source string - EPICS PV name or DRV_INFO string */
NDAttrSource_t sourceType_; /**< Source type */
std::string sourceTypeString_; /**< Source type string */
NDAttributeListNode listNode_; /**< Used for NDAttributeList */
};
Note that it has some private member data of type std::string.
This is what happens when linking dynamically (i.e. EPICS_HOST_ARCH=windows-x64) with the ADSrc library that contains that class on VS2010.
************************************************************
j:\epics\devel\areadetector-2-6\adcore\include\NDAttribute.h(115) : warning C4251: 'NDAttribute::name_' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface
to be used by clients of class 'NDAttribute'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
j:\epics\devel\areadetector-2-6\adcore\include\NDAttribute.h(116) : warning C4251: 'NDAttribute::description_' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to
have dll-interface to be used by clients of class 'NDAttribute'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
j:\epics\devel\areadetector-2-6\adcore\include\NDAttribute.h(119) : warning C4251: 'NDAttribute::string_' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have
dll-interface to be used by clients of class 'NDAttribute'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
j:\epics\devel\areadetector-2-6\adcore\include\NDAttribute.h(120) : warning C4251: 'NDAttribute::source_' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have
dll-interface to be used by clients of class 'NDAttribute'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
j:\epics\devel\areadetector-2-6\adcore\include\NDAttribute.h(122) : warning C4251: 'NDAttribute::sourceTypeString_' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs
to have dll-interface to be used by clients of class 'NDAttribute'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
************************************************************
However, those warnings do not occur when building the library statically, i.e. EPICS_HOST_ARCH=windows-x64-static.
Mark
If one builds Epics V 4 on a windows box with Visual Studio 2013 Community, as either shared libraries or static, you get *hundreds* of warning messages that deal with <something> needing to have dll-interface to be used.
i.e.
warning C4251: 'epics::nt::NTEnum::URI' : class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
needs to have dll-interface to be used by clients of class 'epics::nt::NTEnum'
Does anyone know if this is actually an indication that things will most likely not work if, for example, one were to build AD2-6 with Epics V4 support?
Microsoft claims that the error is thrown when one is not separating the interface from the implementation. If clients should not be able to access these items, they should
be made private and #pragma warning disable C4251 added to source. If they should be accessible, code added to access them.
I’m assuming the #pragma solution is a reasonable solution?