> 2025-09-19  Bruno Haible  <br...@clisp.org>
> 
>         map-c++-tests: Fix compilation error (regression 2025-09-17).
>         * tests/test-map-c++.cc (streq): Remove function.
>         * modules/map-c++-tests (Depends-on): Add stringeq.
> 

This fixed the compilation error (on all platforms). But there still
is a link error, on some platforms (CentOS 7, macOS, OpenBSD).
For example, on OpenBSD:

c++ -Wno-error -Wno-error -g -O2  -L/usr/local/lib -o test-map-c++ 
test-map-c++.o libtests.a ../gllib/libgnu.a libtests.a ../gllib/libgnu.a 
libtests.a  /usr/local/lib/libintl.so.8.0 /usr/local/lib/libiconv.so.7.1 
-Wl,-rpath,/usr/local/lib -lbacktrace -lm -lm -lm -lm -lm -lm -lm -lm -lm -lm 
-lm
ld: warning: vasnprintf.c:403 
(../../gllib/vasnprintf.c:403)(vasnprintf.o:(vasnprintf) in archive 
../gllib/libgnu.a): warning: sprintf() is often misused, please use snprintf()
ld: error: undefined symbol: streq(char const*, char const*)
>>> referenced by gl_map.h:272 (../../gltests/../gllib/gl_map.h:272)
>>>               test-map-c++.o:(main)
c++: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[4]: *** [Makefile:21328: test-map-c++] Error 1

This patch fixes it.


2025-09-19  Bruno Haible  <br...@clisp.org>

        stringeq: Fix use in C++ mode.
        * lib/string.in.h (memeq, streq): Define with "C" linkage.

diff --git a/lib/string.in.h b/lib/string.in.h
index 2c941d08f4..fdcdd21bed 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -417,11 +417,17 @@ _GL_WARN_ON_USE (memchr, "memchr has platform-specific 
bugs - "
 
 /* Are S1 and S2, of size N, bytewise equal?  */
 #if @GNULIB_STRINGEQ@ && !@HAVE_DECL_MEMEQ@
+# ifdef __cplusplus
+extern "C" {
+# endif
 _GL_STRING_INLINE bool
 memeq (void const *__s1, void const *__s2, size_t __n)
 {
   return !memcmp (__s1, __s2, __n);
 }
+# ifdef __cplusplus
+}
+# endif
 #endif
 
 /* Return the first occurrence of NEEDLE in HAYSTACK.  */
@@ -806,11 +812,17 @@ _GL_CXXALIASWARN (strdup);
 
 /* Are strings S1 and S2 equal?  */
 #if @GNULIB_STRINGEQ@ && !@HAVE_DECL_STREQ@
+# ifdef __cplusplus
+extern "C" {
+# endif
 _GL_STRING_INLINE bool
 streq (char const *__s1, char const *__s2)
 {
   return !strcmp (__s1, __s2);
 }
+# ifdef __cplusplus
+}
+# endif
 #endif
 
 /* Append no more than N characters from SRC onto DEST.  */




Reply via email to