Building a testdir for 'isalnum_l' on CentOS 5, I see this link error:

g++  -Wno-error -g -O2  -o test-stdlib-h-c++ test-stdlib-h-c++.o 
test-stdlib-h-c++2.o libtests.a ../gllib/libgnu.a libtests.a ../gllib/libgnu.a 
libtests.a       
test-stdlib-h-c++.o: In function `__static_initialization_and_destruction_0':
/home/bruno/testdir1/build-64/gltests/../../gltests/test-stdlib-h-c++.cc:166: 
undefined reference to `rpl_realloc(void*, unsigned long)'
collect2: ld returned 1 exit status
make[4]: *** [test-stdlib-h-c++] Error 1

The cause is that test-stdlib-h-c++.o needs the symbol rpl_realloc with C++
linkage; however, realloc.o defines the symbol rpl_realloc with C linkage.

This patch fixes it.


2025-02-16  Bruno Haible  <br...@clisp.org>

        realloc: Fix link error in C++ mode on CentOS 5 (regression 2024-11-04).
        * lib/stdlib.in.h (rpl_realloc): Ensure C linkage, not C++ linkage, in
        C++ mode.

diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index 11d337a18a..2077a63fc6 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -1473,11 +1473,17 @@ _GL_WARN_ON_USE (setstate_r, "setstate_r is unportable 
- "
 # if @REPLACE_REALLOC_FOR_REALLOC_POSIX@
 #  if @REPLACE_REALLOC_FOR_REALLOC_POSIX@ == 2
 #   define _GL_INLINE_RPL_REALLOC 1
+#   ifdef __cplusplus
+extern "C" {
+#   endif
 _GL_REALLOC_INLINE void *
 rpl_realloc (void *ptr, size_t size)
 {
   return realloc (ptr, size ? size : 1);
 }
+#   ifdef __cplusplus
+}
+#   endif
 #  endif
 #  if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
         || _GL_USE_STDLIB_ALLOC)




Reply via email to