ludocode / mpack

MPack - A C encoder/decoder for the MessagePack serialization format / msgpack.org[C]
MIT License
521 stars 82 forks source link

mpack compilation error on CentOS 6 #69

Closed edsiper closed 4 years ago

edsiper commented 5 years ago

mpack is a great library and we started the first integration here:

https://github.com/fluent/fluent-bit/commit/3886c226c007a8354727fdb0cc791e26c82bc456

However, we got some build problems on a certain compiler version (gcc on centos 6):

/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c: In function ‘mpack_str_check_no_null’:
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c:847: error: ‘for’ loop initial declarations are only allowed in C99 mode
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c:847: note: use option -std=c99 or -std=gnu99 to compile your code
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c: In function ‘mpack_expect_enum’:
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c:4017: error: ‘for’ loop initial declarations are only allowed in C99 mode
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c: In function ‘mpack_expect_enum_optional’:
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c:4050: error: ‘for’ loop initial declarations are only allowed in C99 mode
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c: In function ‘mpack_node_map_int_impl’:
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c:5827: error: ‘for’ loop initial declarations are only allowed in C99 mode
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c: In function ‘mpack_node_map_uint_impl’:
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c:5858: error: ‘for’ loop initial declarations are only allowed in C99 mode
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c: In function ‘mpack_node_map_str_impl’:
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c:5892: error: ‘for’ loop initial declarations are only allowed in C99 mode
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c: In function ‘mpack_node_enum_optional’:
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.c:5994: error: ‘for’ loop initial declarations are only allowed in C99 mode

this is not a new report, indeed there are previous issues reported on mpack repo:

we can get rid of the problem defining CFLAGS with -std=c99, anyways I see other warnings remain:

/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.h:1218: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.h:1240: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.h:2274: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.h:2292: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.h:3237: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.h:3388: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.h:4314: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.h:4332: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.h:5734: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.h:5753: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
/root/fluent-bit/lib/mpack-amalgamation-1.0/src/mpack/mpack.h:7145: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’

what would be the suggested flags to get rid of warnings ? or can you set the variables on top of the functions ?, looks like a small change that will help to build it on old systems.

ludocode commented 4 years ago

Ah, CentOS 6 has GCC 4.4 which is super old. MPack is written in C99 and I have no plans to add support for C89 or gnu89. On older compilers that default to C89 you need to explicitly configure it for C99 (or C++), and for GCC that's -std=c99.

For the second part of the report, it looks like #pragma GCC diagnostic push isn't supported until GCC 4.6. I removed uses of this on older versions of GCC. This means that warnings that are incompatible with MPack will no longer be disabled automatically within the MPack headers on these old compilers.

You can use the script tools/amalgamate.sh to generate a new amalgamation package from the latest code in the develop branch.

edsiper commented 4 years ago

@ludocode thanks! I've merged latest version in our repo, it looks good now :)