MATIO Compilation Error on MinGW (vasprintf not found)
SLXIO – SIMULINK SLX File I/O Library
Brought to you by:
wissem01
Originally created by: wissem01chiha
Originally owned by: wissem01chiha
Original Isuse https://github.com/tbeu/matio/issues/326
Originally posted by: wissem01chiha
fixed with a workaround, but need more in depth, as matio not yet used in codebase, it can wait
Originally posted by: tbeu
I dug into this and believe I found the root cause. It is a CMake cache collision between json-c and matio, specific to MinGW:
CMakeLists.txtrunslist(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)and thencheck_symbol_exists(vasprintf stdio.h HAVE_VASPRINTF)._GNU_SOURCEdefined, mingw-w64'sstdio.hdeclaresvasprintf(redirected via__MINGW_ASM_CALLto__mingw_vasprintffrom libmingwex), so json-c's check succeeds and storesHAVE_VASPRINTF=1in the shared top-level CMake cache.check_symbol_exists(vasprintf stdio.h HAVE_VASPRINTF)(cmake/compilerOptions.cmake) then sees the cache variable already defined and skips the check entirely, so matio inheritsHAVE_VASPRINTF=1without_GNU_SOURCEbeing defined for its compilation units.vasprintfwithout_GNU_SOURCE, the call atsnprintf/snprintf.c:1453insiderpl_asprintffails withimplicit declaration of function 'vasprintf'. (HAVE_ASPRINTFis correctly not detected, sorpl_asprintfis compiled.)So it is an interaction between json-c's
CMAKE_REQUIRED_DEFINITIONSand CMake's per-variable global check cache, and it only manifests on MinGW because mingw-w64 hidesvasprintfbehind_GNU_SOURCE. matio is tracking this upstream in tbeu/matio#326 (a CI reproduction was added there): https://github.com/tbeu/matio/actions/runs/30849805719/job/91806795254Originally posted by: wissem01chiha
Ah , Thanks very much @tbeu , i got it now, i though that was a nasty mix of cmake configuration flags , but didn't resolve the root cause, that explain lot of things, thanks for your time and, for adding the CI checks in MATIO
Originally posted by: wissem01chiha
does it seem logical to repost this in json-c repository, and fix it there ?
Originally posted by: wissem01chiha
thanks for forking my project @tbeu , however it still in early implementation phase an i am changing a lot in the API and design as well as build scripts and CI
Originally posted by: tbeu
Well, if you remove your workaround and swap configuration such that matio is configured before json-c, you get build errors for json-c, because json-c's fallback static vasprintf conflicts with its own _GNU_SOURCE declaration.
So there is no ordering that works with the current cache behavior:
I have a workaound ready for matio to unset the cached variables, but it only hides the issue. Hence, I am reluctant to push.
Originally posted by: wissem01chiha
Hi , ok no problem , honestly i would touch MATIO at this level , i am planning to fix if i dig more in json-c library build script logic , or replace the hole json-c with more modern third-party that throw away this , however this is not my first issue which related to json-c , it caused me pain in past , i will find a solution , anyway,
thanks very much @tbeu for your time , your project was a source of inspiration for me
Originally posted by: wissem01chiha
if i find a clean solution , i will came back here and post it 😁