#Windows executable crashes on other machines

1 messages · Page 1 of 1 (latest)

grave maple
#

I am trying to build a windows executable that can run on other windows machines, but so far the executable works fine on my machine, while it hangs for 15-20 seconds on other machines and then just exits. My build.zig is the following:

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
        .name = "spacer",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });

    if (optimize != .Debug) {
        exe.subsystem = .Windows;
    }

    // Engine
    const engine = b.createModule(.{
        .root_source_file = .{ .path = "src/engine/engine.zig" },
    });

    exe.root_module.addImport("engine", engine);
    exe.addLibraryPath(.{ .cwd_relative = "external/sdl/lib/x64" });
    exe.linkSystemLibrary("SDL2");
    exe.addLibraryPath(.{ .cwd_relative = "external/sdl-ttf/lib/x64" });
    exe.linkSystemLibrary("SDL2_ttf");
    exe.addLibraryPath(.{ .cwd_relative = "external/sdl-image/lib/x64" });
    exe.linkSystemLibrary("SDL2_image");

    exe.addWin32ResourceFile(.{
        .file = .{ .cwd_relative = "src/spacer.rc" },
    });

    b.getInstallStep().dependOn(&b.addInstallArtifact(
        exe,
        .{ .dest_dir = .{ .override = .{ .custom = "../" } } },
    ).step);
}

And the entrypoint in main.zig is:

extern "kernel32" fn CreateMutexA(lpMutexAttributes: ?*const *opaque {}, bInitialOwner: w.BOOL, lpName: w.LPCSTR) callconv(w.WINAPI) w.HANDLE;
extern "user32" fn MessageBoxA(hwnd: ?w.HWND, lpText: w.LPCSTR, lpCaption: w.LPCSTR, uType: w.UINT) w.INT;

const MessageBox = struct {
    const button_ok: w.UINT = 0x0;
    const icon_error: w.UINT = 0x10;
};

pub export fn wWinMain(_: w.HINSTANCE, _: ?w.HINSTANCE, _: ?w.LPWSTR, _: w.INT) callconv(w.WINAPI) w.INT {
#

The problem isn't missing SDL dlls as those were present in the same directory as the executable on all other machines I tested on.

My machine is an intel CPU Windows 11 while most of the other machines I tested on were running Windows 10 (again Intel laptop CPUs).

broken glacier
#

might be api related, try running it just by double cliking it

#

running windows executables via command line don't show the "functions not found" dialog boxes

grave maple
#

Doesn't run from either CMD or double clicking the exe. In debug mode where CMD is present it just hangs on blank console and closes in 15-30 sec. On release version without CMD it just does nothing and closes (there was no message box error).

broken glacier
#

try to add -Dtarget=x86_64-windows-gnu to your zig build command (in your terminal)

#

sometimes, zig might use instructions that are specific to your cpu to optimize the binary

grave maple
#

Just for the record, it seems to produce the MessageBox even when ran from console. I'll try with the target now

broken glacier
#

try add sdl ttf too

grave maple
#

no that's when I removed it from my system

#

If I have it in the directory it just runs fine, I just wanted to test if CMD really does hid ethe messagebox

broken glacier
#

ok

#

what about now ?

grave maple
#

Worked. Thank you.

broken glacier
#

np 👍