Hello Zig Language Community,
I hope this message finds you well. I am reaching out to seek your expertise regarding a couple of issues I’ve encountered while working with Zig to implement a Lua C module on a Windows environment.
My project aims to create a Lua C module without linking against libc, as the Lua binary itself (lua54.dll) requires libc, and my module only needs to link to lua54.dll and use its provided interfaces. However, I’ve run into a compilation error due to the inclusion of the stdio.h
header file within lua.h
. The error message is as follows:
src\main.zig:2:11: error: C import failed
const c = @cImport({
^~~~~~~~
src\main.zig:2:11: note: libc headers not available; compilation does not link against libc
referenced by:
zig_fx: src\main.zig:8:36
remaining reference traces hidden; use '-freference-trace' to see all reference traces
C:\Devel\MinGW\include/lauxlib.h:13:10: error: 'stdio.h' file not found
#include <stdio.h>
^
To address this, I added lib.linkLibC()
to build.zig
, which is necessary only on the Windows platform. However, this resulted in the final DLL depending on the dynamic-link libraries provided by Windows. Typically, when working with C, I would link against the static MSVC libc library using the /MT
flag, but I have not found a way to pass this flag or an equivalent to the MSVC linker through Zig.
Therefore, I am seeking advice on two fronts:
- Is there a way to compile Zig code that depends only on libc headers without actually linking against libc?
- If that’s not feasible, is there a way to link against a static version of the libc library on Windows, or perhaps use the VC6-style msvcrt.dll library? Additionally, is it possible to specify the use of MinGW’s runtime with Zig?
Any guidance or suggestions you could provide would be greatly appreciated. I am eager to learn and find a solution that allows my module to work seamlessly.
Thank you for your time and assistance.
Best regards,
Xavier Wang.