#error: `Windows.h` file not found

1 messages · Page 1 of 1 (latest)

uncut maple
#

Hello everyone. I'm trying to cross compile from Linux to Windows, but I'm having issues importing the Windows header:

install
└─ install zig-linux-windows
   └─ zig build-exe zig-linux-windows Debug x86_64-windows-msvc 2 errors
src/main.zig:1:17: error: C import failed
const windows = @cImport({
                ^~~~~~~~
referenced by:
    main: src/main.zig:6:5
    callMain: /usr/lib/zig/std/start.zig:511:32
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
/home/fox/Documents/Code/zig-linux-windows/zig-cache/o/99216ed7f9b7bae2e006adb4834b379a/cimport.h:1:10: error: 'Windows.h' file not found
#include <Windows.h>
         ^
error: the following command failed with 2 compilation errors:
/usr/bin/zig build-exe -ODebug -target x86_64-windows-msvc -mcpu baseline -Mroot=/home/fox/Documents/Code/zig-linux-windows/src/main.zig -lc --cache-dir /home/fox/Documents/Code/zig-linux-windows/zig-cache --global-cache-dir /home/fox/.cache/zig --name zig-linux-windows --listen=- 
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install zig-linux-windows transitive failure
   └─ zig build-exe zig-linux-windows Debug x86_64-windows-msvc 2 errors
error: the following build command failed with exit code 1:
/home/fox/Documents/Code/zig-linux-windows/zig-cache/o/39717c83fd6ea5ab5c327375b6a2d9b8/build /usr/bin/zig /home/fox/Documents/Code/zig-linux-windows /home/fox/Documents/Code/zig-linux-windows/zig-cache /home/fox/.cache/zig --seed 0xa3efff9b -Z2149fe5ce863e078

I'm not sure why this is happening, as I've linked libc to the executable.

#

This is main.zig

const windows = @cImport({
    @cInclude("Windows.h");
});

pub fn main() !void {
    windows.Sleep(5000);
}

This is build.zig

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.resolveTargetQuery(.{
        .cpu_arch = .x86_64,
        .os_tag = .windows,
        .abi = .msvc,
    });

    const optimize = b.standardOptimizeOption(.{});

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

    // Make sure Windows.h is available
    exe.linkLibC();

    b.installArtifact(exe);
}
#

and I also tried using a lowercase windows.h which doesn't work for some reason as well

ionic moon
#

Try .abi = .gnu in your build.zig. and the lowercase w as you said

uncut maple
#

thanks!

#

any idea why it doesn't work on msvc abi though?

ionic moon