Skip to contentSkip to conversation

windows: build error with mingw debug

PATCH Applied Nick Connolly 2 participants 2 messages Nov 27, 2020 – Dec 7, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 windows: build error with mingw debug

Compiling with MinGW in --buildtype=debug produces a redefinition error for strncasecmp.

The root cause is that rte_os.h shouldn't be injecting POSIX definitions into the environment. It is the applications responsibility to decide how to handle missing functionality.

Resolving this properly will require further work, but in the meantime wrap all such definitions with #ifndef/#endif. This resolves the specific issue with strncasecmp and handles similar issues that applications may encounter.

Fixes e8428a9d89f1 ("eal/windows: add some basic functions and macros")
---
 lib/librte_eal/windows/include/rte_os.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
lib/librte_eal/windows/include/rte_os.h +22 -0
index 569ed92d5..ea3fe60e5 100644
@@ -25,22 +25,42 @@ extern "C" {
 #define PATH_MAX _MAX_PATH
 #endif
 
+#ifndef sleep
 #define sleep(x) Sleep(1000 * (x))
+#endif
 
+#ifndef strerror_r
 #define strerror_r(a, b, c) strerror_s(b, c, a)
+#endif
 
+#ifndef strdup
 /* strdup is deprecated in Microsoft libc and _strdup is preferred */
 #define strdup(str) _strdup(str)
+#endif
 
+#ifndef strtok_r
 #define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
+#endif
 
+#ifndef index
 #define index(a, b)     strchr(a, b)
+#endif
+
+#ifndef rindex
 #define rindex(a, b)    strrchr(a, b)
+#endif
 
+#ifndef strncasecmp
 #define strncasecmp(s1, s2, count)        _strnicmp(s1, s2, count)
+#endif
 
+#ifndef close
 #define close _close
+#endif
+
+#ifndef unlink
 #define unlink _unlink
+#endif
 
 /* cpu_set macros implementation */
 #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
@@ -89,7 +109,9 @@ eal_strerror(int code)
 	return buffer;
 }
 
+#ifndef strerror
 #define strerror eal_strerror
+#endif
 
 #endif /* RTE_TOOLCHAIN_GCC */
 
Signature · 1 line
2.25.1
#1 lore raw

27/11/2020 12:07, Nick Connolly:

Quoted 12 lines

Compiling with MinGW in --buildtype=debug produces a redefinition error for strncasecmp.

The root cause is that rte_os.h shouldn't be injecting POSIX definitions into the environment. It is the applications responsibility to decide how to handle missing functionality.

Resolving this properly will require further work, but in the meantime wrap all such definitions with #ifndef/#endif. This resolves the specific issue with strncasecmp and handles similar issues that applications may encounter.

Quoted 4 lines
Fixes e8428a9d89f1 ("eal/windows: add some basic functions and macros")

It looks as a good fix to me.
I'm surprised there was no review.

Applied, thanks