Ucrt_sscanf vs mingw_sscanf

I’m building a shared library, this shared library has a bunch of c code including imgui, that calls internally sscanf that for some reason crashes if I attach a .root_source_file = b.path(“file.zig“) to the library root_module, the file.zig is empty by the way, commening this line soves the issue, but I need that file to be included…

So I’m trying to make a small repro, to do a bug report but my repro calls the ucrt_sscanf while main main project calls mingw_sscanf and I don’t know why or how to do change the implementations.

Any ideas?

Let me explain my setup a little better:

I have a bootstrap.exe, core.dll and a game.dll, the bootstrap loads both core and game, the core.dll contains all game’s dependencies and static variables, game, contains my game logic, and because of how I setup things game can be hot-reloaded, so thats my main goal.

Problem is: calling a function in core that calls sscanf from causes a crash inside atexit function, the issue happens only if core has a mix of zig and c/cpp code, isolating one of the other is fine, and like I mention before doing this causes the sscanf function to change implemetations, so my guess is that something is forcing zig to include 2 crts maybe at the same time

Edit: calling it from bootstrap.exe of game.dll casues the crash

I’m impressed by the amount of technologic nescessary to parse a string. I could have been a rocket scientist, it would be easier…

Just an idea, but are you telling Zig to build for the same target as the c/cpp code? Based on the error, it seems like your c/c++ is using mingw, while the zig is defaulting to a different c runtime. Try using the mingw target for your zig code.

Why are you putting an empty file as the root source file? Are you trying to embed it?

  1. I’m using the same ResolvedTarget for everything, dispite that zig build system does something weird if I include raylib + root_source_file (didn’t try other combinations) in the same compile step, heres my build script

build.zig (10.1 KB)

  1. the “file.zig” in the build is actually called “expo.zig“ is not empty, but even if was, having the root_source_file assigned is what causing the issue. If I build 2 different dlls one for the c (core.dll) and other for the zig (core2.dll) the issue desapears.

Explicitly declaring extern "C" int sscanf(const char *buf, const char *format, ...); instead of using stdio.h solves the issue,

What does this means, the header is worng, maybe a bad define?

Raylib build system defined _GNU_SOURCE that was the source of the issue.

https://codeberg.org/ziglang/zig/issues/32116

1 Like