From fb51b0e933bcd146797c8f24c1dd471f0c532470 Mon Sep 17 00:00:00 2001 From: Kevin Lenzo Date: Sun, 16 Aug 2026 19:02:17 -0400 Subject: [PATCH] Use the MSVC pipe function spellings in pio.c The Win32 C runtime exports the pipe functions as _popen and _pclose. The POSIX spellings are declared in , so HAVE_POPEN is set and the code compiles, but they are not resolvable when linking a shared library; an MSVC DLL build of the pocketsphinx library therefore fails with LNK2019 on popen. fclose_comp already used _pclose under _WIN32, but fopen_comp still called bare popen, so the two sides disagreed. Map popen and pclose to the underscore spellings on Win32 in one place, and drop the now-redundant inline _pclose guard, so both pipe calls use the spelling the CRT exports. The guard is inert off Win32, leaving behavior on other platforms unchanged. --- src/util/pio.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/util/pio.c b/src/util/pio.c index ac37596e1..d70791810 100644 --- a/src/util/pio.c +++ b/src/util/pio.c @@ -67,6 +67,16 @@ #include "util/strfuncs.h" #include "util/ckd_alloc.h" +/* The MSVC/Win32 C runtime exports the pipe functions as _popen/_pclose. + * The POSIX spellings are declared in (so HAVE_POPEN is defined + * and the code compiles) but are not resolvable when linking a shared + * library, which breaks an MSVC DLL build. Map to the underscore + * spellings on Win32, matching the guard already used for _pclose. */ +#if defined(_WIN32) && !defined(__SYMBIAN32__) +#define popen _popen +#define pclose _pclose +#endif + #ifndef EXEEXT #define EXEEXT "" #endif @@ -186,11 +196,7 @@ fclose_comp(FILE * fp, int32 ispipe) { if (ispipe) { #ifdef HAVE_POPEN -#if defined(_WIN32) && (!defined(__SYMBIAN32__)) - _pclose(fp); -#else pclose(fp); -#endif #endif } else