pdf-tools
pdf-tools copied to clipboard
Fix build failure due to vasprintf on Windows
MinGW’s compiler (GCC 14.2.0) errors out compiling synctex_parser.c.
synctex_parser.c: In function '_synctex_updater_print_gz':
synctex_parser.c:8448:13: error: implicit declaration of function
'vasprintf'; did you mean 'vsprintf'?
8448 | if (vasprintf(&buffer, format, va) < 0) {
| ^~~~~~~~~
| vsprintf
vasprintf is a custom function (not the standard vsprintf) that’s defined in the same translation unit a few lines above.
However its definition is wrapped within a if defined(_MSC_VER) i.e. it’s only enabled when compiled with MSVC compiler.
This fix implements vasprintf (available on Linux and macOS) for Windows irrespective of compiler/toolchain used. I've implemented it using the standard C function vsnprintf.
Fixes #286.
i am getting the same error with a compiler different than MinGW, but the https://github.com/vedang/pdf-tools/pull/295 only addresses the MinGW scenario.
ifndef HAVE_VASPRINTF should fix the issue as per
https://lists.gnu.org/archive/html/emacs-elpa-diffs/2022-08/msg01485.html https://lists.gnu.org/archive/html/emacs-elpa-diffs/2022-08/msg01533.html
The function vasprintf, available on Linux and macOS, is unavailable on Windows irrespective of compiler.
I've updated the PR to address all Windows builds in general; not specifically MinGW or MSVC. I've changed the implementation to use the standard C library function vsnprintf to implement this vasprintf which mimics the behaviour of the ones available on Linux/macOS.
@danielkrizian This should address your issue; please let me know if it worked for you. Thank you!
Thank you @legends2k , that fixed it for me!
Note: Consider merging PR #308 as it's a superset of this.
This fix still works as of 2025-10-31 on Windows 11. Is there some work that needs to be done before this can be accepted as a PR?