Skip to content

Use the MSVC pipe function spellings in pio.c - #506

Open
lenzo-ka wants to merge 1 commit into
cmusphinx:mainfrom
lenzo-ka:msvc_pipe_spelling
Open

Use the MSVC pipe function spellings in pio.c#506
lenzo-ka wants to merge 1 commit into
cmusphinx:mainfrom
lenzo-ka:msvc_pipe_spelling

Conversation

@lenzo-ka

Copy link
Copy Markdown
Contributor

The Microsoft C runtime exports the pipe functions as _popen/_pclose. pio.c already used _pclose on the close side under _WIN32, but fopen_comp() called bare popen(), so an MSVC shared-library build failed to link:

pio.obj : error LNK2019: unresolved external symbol popen referenced in function fopen_comp
pocketsphinx.dll : fatal error LNK1120: 1 unresolved externals

This maps popen/pclose to the underscore spellings on Win32 in one place and drops the now-redundant inline _pclose guard, so both pipe calls use the spelling the CRT exports. The guard is inert off Win32; behavior on other platforms is unchanged.

Verified by linking the pipe construct as a DLL under MSVC: it fails with LNK2019 before the change and links cleanly after. A non-Windows build is unaffected — the preprocessed translation unit is identical to before the change off _WIN32.

Fixes #505

The Win32 C runtime exports the pipe functions as _popen and _pclose.
The POSIX spellings are declared in <stdio.h>, 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

MSVC shared-library build fails to link: pio.c calls popen/pclose but the CRT exports _popen/_pclose

1 participant