Building a testdir of module 'endian' on CentOS 5, I get this build error: gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/home/bruno/inst-x86_64-64/include -Wall -Wno-error -g -O -MT test-endian.o -MD -MP -MF .deps/test-endian.Tpo -c -o test-endian.o ../../gltests/test-endian.c ../../gltests/test-endian.c: In function ‘test_convert_constant’: ../../gltests/test-endian.c:80: warning: implicit declaration of function ‘be16toh’ ../../gltests/test-endian.c:81: warning: implicit declaration of function ‘htobe16’ ../../gltests/test-endian.c:82: warning: implicit declaration of function ‘le16toh’ ../../gltests/test-endian.c:83: warning: implicit declaration of function ‘htole16’ ../../gltests/test-endian.c:86: warning: implicit declaration of function ‘be32toh’ ../../gltests/test-endian.c:87: warning: implicit declaration of function ‘htobe32’ ../../gltests/test-endian.c:88: warning: implicit declaration of function ‘le32toh’ ../../gltests/test-endian.c:89: warning: implicit declaration of function ‘htole32’ ../../gltests/test-endian.c:93: warning: implicit declaration of function ‘be64toh’ ../../gltests/test-endian.c:93: warning: comparison is always false due to limited range of data type ../../gltests/test-endian.c:95: warning: implicit declaration of function ‘htobe64’ ../../gltests/test-endian.c:95: warning: comparison is always false due to limited range of data type ../../gltests/test-endian.c:97: warning: implicit declaration of function ‘le64toh’ ../../gltests/test-endian.c:97: warning: comparison is always false due to limited range of data type ../../gltests/test-endian.c:99: warning: implicit declaration of function ‘htole64’ ../../gltests/test-endian.c:99: warning: comparison is always false due to limited range of data type mv -f .deps/test-endian.Tpo .deps/test-endian.Po gcc -std=gnu99 -Wno-error -g -O -L/home/bruno/inst-x86_64-64/lib -o test-endian test-endian.o libtests.a ../gllib/libgnu.a libtests.a ../gllib/libgnu.a libtests.a test-endian.o: In function `test_convert_constant': /home/bruno/testdir1/build-64/gltests/../../gltests/test-endian.c:80: undefined reference to `be16toh' /home/bruno/testdir1/build-64/gltests/../../gltests/test-endian.c:81: undefined reference to `htobe16' /home/bruno/testdir1/build-64/gltests/../../gltests/test-endian.c:82: undefined reference to `le16toh' /home/bruno/testdir1/build-64/gltests/../../gltests/test-endian.c:83: undefined reference to `htole16' /home/bruno/testdir1/build-64/gltests/../../gltests/test-endian.c:86: undefined reference to `be32toh' /home/bruno/testdir1/build-64/gltests/../../gltests/test-endian.c:87: undefined reference to `htobe32' /home/bruno/testdir1/build-64/gltests/../../gltests/test-endian.c:88: undefined reference to `le32toh' /home/bruno/testdir1/build-64/gltests/../../gltests/test-endian.c:89: undefined reference to `htole32' /home/bruno/testdir1/build-64/gltests/../../gltests/test-endian.c:93: undefined reference to `be64toh' collect2: ld returned 1 exit status make[4]: *** [test-endian] Error 1
The cause is a wrong configure test: checking if endian.h defines functions and macros... yes when in fact endian.h does NOT declare or define the various functions. This patch fixes it. 2024-12-28 Bruno Haible <br...@clisp.org> endian: Fix link error on CentOS 5. * m4/endian_h.m4 (gl_ENDIAN_H): Use AC_LINK_IFELSE, not AC_COMPILE_IFELSE. diff --git a/m4/endian_h.m4 b/m4/endian_h.m4 index 712c435fe8..4dcaf1c790 100644 --- a/m4/endian_h.m4 +++ b/m4/endian_h.m4 @@ -1,5 +1,5 @@ # endian_h.m4 -# serial 5 +# serial 6 dnl Copyright 2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -34,7 +34,7 @@ AC_DEFUN_ONCE([gl_ENDIAN_H] AC_CACHE_CHECK([if endian.h defines functions and macros], [gl_cv_header_working_endian_h], [gl_cv_header_working_endian_h=no - AC_COMPILE_IFELSE( + AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[ #include <endian.h> @@ -103,7 +103,7 @@ AC_DEFUN_ONCE([gl_ENDIAN_H] AC_CACHE_CHECK([if sys/endian.h defines functions and macros], [gl_cv_header_working_sys_endian_h], [gl_cv_header_working_sys_endian_h=no - AC_COMPILE_IFELSE( + AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[ #include <sys/endian.h>