pdf-tools icon indicating copy to clipboard operation
pdf-tools copied to clipboard

Fix build failure due to vasprintf on Windows

Open legends2k opened this issue 1 year ago • 4 comments

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.

legends2k avatar Sep 05 '24 05:09 legends2k

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

danielkrizian avatar Oct 21 '24 16:10 danielkrizian

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!

legends2k avatar Oct 22 '24 07:10 legends2k

Thank you @legends2k , that fixed it for me!

chuchana avatar Nov 29 '24 20:11 chuchana

Note: Consider merging PR #308 as it's a superset of this.

legends2k avatar Dec 26 '24 21:12 legends2k

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?

GarnetKoebelSAF avatar Oct 31 '25 15:10 GarnetKoebelSAF