scrapinghub / python-crfsuite

A python binding for crfsuite
MIT License
768 stars 223 forks source link

Fails to build with GCC 14 due to -Wimplicit-function-declaration #158

Open glaubitz opened 1 month ago

glaubitz commented 1 month ago

Trying to build python-crfsuite with GCC 14 fails because of the enforced -Wimplicit-function-declaration:

[   42s] gcc -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -DOPENSSL_LOAD_CONF -fwrapv -fno-semantic-interposition -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -IVendor/ -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -IVendor/ -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -g -fPIC -Icrfsuite/include/ -Icrfsuite/lib/cqdb/include -Iliblbfgs/include -Ipycrfsuite -I/usr/include/python3.10 -c -std=c99 crfsuite/lib/crf/src/crf1d_context.c -o build/temp.linux-x86_64-cpython-310/crfsuite/lib/crf/src/crf1d_context.o
[   42s] In file included from crfsuite/lib/crf/src/crf1d_context.c:47:
[   42s] crfsuite/lib/crf/src/vecmath.h: In function ‘_aligned_malloc’:
[   42s] crfsuite/lib/crf/src/vecmath.h:50:15: error: implicit declaration of function ‘posix_memalign’ [-Wimplicit-function-declaration]
[   42s]    50 |     int ret = posix_memalign(&p, alignment, size);
[   42s]       |               ^~~~~~~~~~~~~~
[   42s] crfsuite/lib/crf/src/crf1d_context.c: In function ‘crf1dc_new’:
[   42s] crfsuite/lib/crf/src/crf1d_context.c:71:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
[   42s]    71 |         if (ret = crf1dc_set_num_items(ctx, T)) {
[   42s]       |             ^~~
[   42s] crfsuite/lib/crf/src/crf1d_context.c: In function ‘crf1dc_score’:
[   42s] crfsuite/lib/crf/src/crf1d_context.c:440:15: warning: unused variable ‘L’ [-Wunused-variable]
[   42s]   440 |     const int L = ctx->num_labels;
[   42s]       |               ^
[   42s] crfsuite/lib/crf/src/crf1d_context.c:438:38: warning: unused variable ‘cur’ [-Wunused-variable]
[   42s]   438 |     const floatval_t *state = NULL, *cur = NULL, *trans = NULL;
[   42s]       |                                      ^~~
[   42s] error: command '/usr/bin/gcc' failed with exit code 1

To reproduce, build with GCC 14 as the default C/C++ compiler.

glaubitz commented 4 weeks ago

As a heads-up, this is fixed by adding -D_POSIX_C_SOURCE=200112L to CFLAGS.

The proper fix would probably be not using posix_memalloc() until Python upstream switches to a newer _POSIX_C_SOURCE.