The following Zig program builds and runs on my laptop, as expected. (Per the first screenshot.)
const std = @import("std");
pub fn main() void {
var x : u32 = 1;
x += 1;
std.debug.print("x is: {}\n", .{x});
}
However, when I copy the .exe to another laptop (also running Windows 10 on a x64 CPU) the program fails to run because of an illegal instruction: vpbroadcastb xmm0, edx (see the second screenshot).
Why is printx.exe not portable? How can I build print.exe so that it will work when I transfer it to the other laptop?
For reference, I built the program on a Framework with a Intel 11th Gen i5-1135G7 CPU. The other laptop is a HP Pavillion with a Intel i5-7200U.
Here's my build script.
const std = @import("std");
pub fn build(b : *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "printx",
.root_source_file = b.path("main.zig"),
.target = target,
.optimize = optimize,
});
const install_artifact = b.addInstallArtifact(exe, .{
.dest_dir = .{ .override = .prefix },
});
b.getInstallStep().dependOn(&install_artifact.step);
}