ziglua icon indicating copy to clipboard operation
ziglua copied to clipboard

Error creating shared library on Windows 11

Open maxxnino opened this issue 11 months ago • 1 comments

I attempted to create a shared library, but encountered an error when running zig build. I’m currently using Windows 11 and zig version 0.12.0-dev.3212+40e64245f.

zig build                       
install
└─ install zlo
   └─ zig build-lib zlo Debug native 1 errors
error: lld-link: ___chkstk_ms was replaced
error: the following command failed with 1 compilation errors:
//build.zig
pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    const lib = b.addSharedLibrary(.{
        .name = "zlo",
        .root_source_file = .{ .path = "src/root.zig" },
        .target = target,
        .optimize = optimize,
    });
    const ziglua = b.dependency("ziglua", .{
        .target = target,
        .optimize = optimize,
        .lang = .lua53,
        .shared = true,
    });
    lib.root_module.addImport("ziglua", ziglua.module("ziglua"));
    b.installArtifact(lib);
}
//src/root.zig
const ziglua = @import("ziglua");
fn zlo(lua: *ziglua.Lua) i32 {
    lua.newLib(&.{
        .{ .name = "add", .func = ziglua.wrap(add) },
    });
    return 1;
}
fn add(lua: *ziglua.Lua) i32 {
    const a = lua.toInteger(1) catch 0;
    const b = lua.toInteger(2) catch 0;
    lua.pushInteger(a + b);
    return 1;
}
comptime {
    _ = ziglua.exportFn("zlo", zlo);
}

maxxnino avatar Mar 12 '24 03:03 maxxnino

Hmmm. I don't get a compile error on macOS, and I don't have a windows zig dev environment set up.

From some initial digging it seems that ___chkstk_ms is a libgcc function for windows. I wonder if you need to do lib.linkLibC(); in your build.zig file, but that is just a wild guess.

I can take a closer look soonish, but it may take me some days to get things setup on my windows pc.

natecraddock avatar Mar 16 '24 20:03 natecraddock

This was merged last week https://github.com/ziglang/zig/pull/20138

I just setup a dev environment on Windows and was able to compile your example code! So it looks like you need to either wait for Zig 0.14.0 or use a dev build.

Feel free to comment if you are still having issues

natecraddock avatar Jul 19 '24 06:07 natecraddock