C++ compilation fails because of the declaration of SOPC_EncodeableType
Problem
Compilation of our C++ project using the S2OPC OPCUA Toolkit fails with the following message:
/usr/local/include/s2opc/common/sopc_encodeabletype.h:112:3: error: conflicting declaration ‘typedef const struct SOPC_EncodeableType SOPC_EncodeableType’
} SOPC_EncodeableType;
^~~~~~~~~~~~~~~~~~~
/usr/local/include/s2opc/common/sopc_encodeabletype.h:97:22: note: previous declaration as ‘struct SOPC_EncodeableType’
typedef const struct SOPC_EncodeableType
^~~~~~~~~~~~~~~~~~~
This appears to be a problem with C++ specifically. A test program written in C compiles without error.
Environment
- Ubuntu 18.04.2 LTS (Bionic Beaver)
- gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
- C++ versions: -std=c++03, -std=c++11, -std=c++14, -std=c++17
Workaround
Edit the include file sopc_encodeabletype.h. Remove const from typedef const struct SOPC_EncodeableType. The end result is:
typedef struct SOPC_EncodeableType
{
char* TypeName;
uint32_t TypeId;
uint32_t BinaryEncodingTypeId;
uint32_t XmlEncodingTypeId;
char* NamespaceUri;
size_t AllocationSize;
SOPC_EncodeableObject_PfnInitialize* Initialize;
SOPC_EncodeableObject_PfnClear* Clear;
SOPC_EncodeableObject_PfnGetSize* GetSize;
SOPC_EncodeableObject_PfnEncode* Encode;
SOPC_EncodeableObject_PfnDecode* Decode;
int32_t NoOfFields;
const SOPC_EncodeableType_FieldDescriptor* Fields;
} SOPC_EncodeableType;
The application compiled this way appears to function properly.