compile error: type of bit-field ‘padding’ is a GCC extension [-Werror=pedantic]
Description
Compile open62541 from source code (open62541-pack-v1.3.3.zip) produce some gcc extention related errors.
Background Information / Reproduction Steps
Decompress source code
unzip open62541-pack-v1.3.3.zip
Compile in build directory
cd open62541-pack-v1.3.3
mkdir build
cd build
cmake3 ..
make
Produce compile errors
[root@localhost build]# make
Scanning dependencies of target open62541-generator-types
[ 2%] Generating src_generated/open62541/types_generated.c, src_generated/open62541/types_generated.h, src_generated/open62541/types_generated_handling.h
[ 2%] Built target open62541-generator-types
Scanning dependencies of target open62541-generator-statuscode
[ 4%] Generating src_generated/open62541/nodeids.h
[ 6%] Generating src_generated/open62541/statuscodes.h, src_generated/open62541/statuscodes.c
[ 6%] Built target open62541-generator-statuscode
Scanning dependencies of target open62541-generator-transport
[ 6%] Generating src_generated/open62541/transport_generated.c, src_generated/open62541/transport_generated.h, src_generated/open62541/transport_generated_handling.h
[ 6%] Built target open62541-generator-transport
Scanning dependencies of target open62541-generator-namespace
[ 6%] Generating src_generated/open62541/namespace0_generated.c, src_generated/open62541/namespace0_generated.h
INFO:__main__:Preprocessing /tmp/open62541-pack-v1.3.3/tools/schema/Opc.Ua.NodeSet2.Reduced.xml
INFO:__main__:Preprocessing /tmp/open62541-pack-v1.3.3/tools/schema/Opc.Ua.NodeSet2.EventsMinimal.xml
INFO:__main__:Preprocessing /tmp/open62541-pack-v1.3.3/tools/schema/Opc.Ua.NodeSet2.Part8_Subset.xml
INFO:__main__:Generating Code for Backend: open62541
INFO:__main__:NodeSet generation code successfully printed
[ 6%] Built target open62541-generator-namespace
Scanning dependencies of target open62541-code-generation
[ 6%] Built target open62541-code-generation
Scanning dependencies of target open62541-object
[ 8%] Building C object CMakeFiles/open62541-object.dir/src/ua_types.c.o
In file included from /tmp/open62541-pack-v1.3.3/src/ua_types.c:18:0:
/tmp/open62541-pack-v1.3.3/include/open62541/types.h: In function ‘UA_EXPANDEDNODEID_NODEID’:
/tmp/open62541-pack-v1.3.3/include/open62541/types.h:550:5: error: missing braces around initializer [-Werror=missing-braces]
UA_ExpandedNodeId id = {0}; id.nodeId = nodeId; return id;
^
/tmp/open62541-pack-v1.3.3/include/open62541/types.h:550:5: error: (near initialization for ‘id.nodeId’) [-Werror=missing-braces]
/tmp/open62541-pack-v1.3.3/include/open62541/types.h:550:5: error: missing initializer for field ‘namespaceUri’ of ‘UA_ExpandedNodeId’ [-Werror=missing-field-initializers]
/tmp/open62541-pack-v1.3.3/include/open62541/types.h:482:15: note: ‘namespaceUri’ declared here
UA_String namespaceUri;
^
/tmp/open62541-pack-v1.3.3/include/open62541/types.h: At top level:
/tmp/open62541-pack-v1.3.3/include/open62541/types.h:981:5: error: type of bit-field ‘padding’ is a GCC extension [-Werror=pedantic]
UA_Byte padding : 6; /* How much padding is there before this
^
/tmp/open62541-pack-v1.3.3/include/open62541/types.h:989:5: error: type of bit-field ‘isArray’ is a GCC extension [-Werror=pedantic]
UA_Byte isArray : 1; /* The member is an array */
^
/tmp/open62541-pack-v1.3.3/include/open62541/types.h:990:5: error: type of bit-field ‘isOptional’ is a GCC extension [-Werror=pedantic]
UA_Byte isOptional : 1; /* The member is an optional field */
^
/tmp/open62541-pack-v1.3.3/src/ua_types.c:41:1: error: missing braces around initializer [-Werror=missing-braces]
const UA_ExpandedNodeId UA_EXPANDEDNODEID_NULL = {0};
^
/tmp/open62541-pack-v1.3.3/src/ua_types.c:41:1: error: (near initialization for ‘UA_EXPANDEDNODEID_NULL.nodeId’) [-Werror=missing-braces]
/tmp/open62541-pack-v1.3.3/src/ua_types.c:41:1: error: missing initializer for field ‘namespaceUri’ of ‘UA_ExpandedNodeId’ [-Werror=missing-field-initializers]
In file included from /tmp/open62541-pack-v1.3.3/src/ua_types.c:18:0:
/tmp/open62541-pack-v1.3.3/include/open62541/types.h:482:15: note: ‘namespaceUri’ declared here
UA_String namespaceUri;
^
cc1: error: unrecognized command line option "-Wno-static-in-inline" [-Werror]
cc1: all warnings being treated as errors
make[2]: *** [CMakeFiles/open62541-object.dir/src/ua_types.c.o] Error 1
make[1]: *** [CMakeFiles/open62541-object.dir/all] Error 2
make: *** [all] Error 2
For the error: missing braces around initializer [-Werror=missing-braces]
This error is already fixed, see Fix error: missing braces around initializer [-Werror=missing-braces] #4907.
Merge the fix. Then rebuild, show errors as below
[root@localhost build]# make
[ 2%] Built target open62541-generator-types
[ 2%] Built target open62541-generator-namespace
[ 6%] Built target open62541-generator-statuscode
[ 6%] Built target open62541-generator-transport
[ 6%] Built target open62541-code-generation
Scanning dependencies of target open62541-object
[ 8%] Building C object CMakeFiles/open62541-object.dir/src/ua_types.c.o
In file included from /root/open63541/open62541-pack-v1.3.3/src/ua_types.c:18:0:
/root/open63541/open62541-pack-v1.3.3/include/open62541/types.h:981:5: error: type of bit-field ‘padding’ is a GCC extension [-Werror=pedantic]
UA_Byte padding : 6; /* How much padding is there before this
^
/root/open63541/open62541-pack-v1.3.3/include/open62541/types.h:989:5: error: type of bit-field ‘isArray’ is a GCC extension [-Werror=pedantic]
UA_Byte isArray : 1; /* The member is an array */
^
/root/open63541/open62541-pack-v1.3.3/include/open62541/types.h:990:5: error: type of bit-field ‘isOptional’ is a GCC extension [-Werror=pedantic]
UA_Byte isOptional : 1; /* The member is an optional field */
^
cc1: error: unrecognized command line option "-Wno-static-in-inline" [-Werror]
cc1: all warnings being treated as errors
make[2]: *** [CMakeFiles/open62541-object.dir/src/ua_types.c.o] Error 1
make[1]: *** [CMakeFiles/open62541-object.dir/all] Error 2
make: *** [all] Error 2
BTW, compile master branch source code can reproduce.
cmake and gcc version:
[root@xphobia build]# cmake3 --version
cmake3 version 3.17.5
CMake suite maintained and supported by Kitware (kitware.com/cmake).
[root@xphobia build]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Checklist
Please provide the following information:
- [x] open62541 Version (release number or git tag): open62541-pack-v1.3.3.zip
- [ ] Other OPC UA SDKs used (client or server):
- [x] Operating system: CentOS Linux release 7.6.1810
- [ ] Logs (with
UA_LOGLEVELset as low as necessary) attached - [ ] Wireshark network dump attached
- [ ] Self-contained code example attached
- [ ] Critical issue
gcc 4.8 is very old. The fix would be to use a bit field over (signed) int. I’m hesitant as this would increase the binary size quite a bit.
can you upgrade to a more recent gcc or disable that warning for the open62541 code?
the generated code is good with all gcc versions we have seen so far.