Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build failure due to vasprintf on Windows #295

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

legends2k
Copy link

@legends2k legends2k commented Sep 5, 2024

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.

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
enables it also for MinGW compilers.
@danielkrizian
Copy link

i am getting the same error with a compiler different than MinGW, but the #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

`vasprintf` is a function available on Linux and macOS but not in
Windows.  Instead of restricting it for MSVC and MinGW, enable it for
all compilers using standard C library function `vsnprintf`.
@legends2k
Copy link
Author

legends2k commented Oct 22, 2024

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 legends2k changed the title Fix MinGW build failure due to vasprintf Fix build failure due to vasprintf on Windows Oct 22, 2024
@chuchana
Copy link

Thank you @legends2k , that fixed it for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

synctex_parser.c:8448:13: error: implicit declaration of function 'vasprintf'
3 participants