0

I'm at linux and want to cross compile for windows, I've the below that is working file for building the executable at linux:

pub fn build(b: *std.build.Builder) void {

    const target = b.standardTargetOptions(.{});

    // const target = "x86_64-windows";


    const mode = b.standardReleaseOptions();

    const exe = b.addExecutable("Zig", "src/main.zig");
    exe.setTarget(target);
    exe.setBuildMode(mode);
    exe.install();
}

I tried to use const target = "x86_64-windows"; but it failed telling that error: expected type 'zig.CrossTarget', found '*const [14:0]u8'

Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203

1 Answers1

2

you need to pass a CrossTarget.

const target = std.zig.CrossTarget{ .os_tag = .windows, .cpu_arch = .x86_64 };

also as @ad-absurdum said you can just run zig build -Dtarget=x86_64-windows

Ali Chraghi
  • 613
  • 6
  • 16