Skip to content

Hello World sample doesn't work in Windows #438

Open
@ZeikJT

Description

The example given here: https://ziglang.org/learn/samples/#hello

As a beginner in zig, running it and seeing this mess wasn't fun:

lib\std\os\windows.zig:2126:13: error: unable to evaluate comptime expression
            asm (
            ^~~
lib\std\os\windows.zig:2135:15: note: called at comptime from here
    return teb().ProcessEnvironmentBlock;
           ~~~^~
lib\std\io.zig:19:27: note: called at comptime from here
        return windows.peb().ProcessParameters.hStdOutput;
               ~~~~~~~~~~~^~
lib\std\io.zig:30:40: note: called at comptime from here
    return .{ .handle = getStdOutHandle() };
                        ~~~~~~~~~~~~~~~^~
C:\Users\zeik\Documents\zig-testing\test.zig:3:32: note: called at comptime from here
const stdout = std.io.getStdOut().writer();
               ~~~~~~~~~~~~~~~~^~
C:\Users\zeik\Documents\zig-testing\test.zig:3:41: note: initializer of container-level variable must be comptime-known
const stdout = std.io.getStdOut().writer();
               ~~~~~~~~~~~~~~~~~~~~~~~~~^~

I usually assume hello world is the baseline for getting started and this was a shock. Had I misconfigured something? How? zig was a single executable, the sample on the landing page which was much more complicated worked fine.

I eventually dug up an old closed issue that explained the problem: ziglang/zig#6845 (comment)
The solution was really simple, if a bit gross, and moving that getStdOut call into the function did indeed fix the issue.

But might be worth mentioning in a note on the page or having both examples? zig beginners will struggle unnecessarily otherwise. Thanks!

EDIT: Just noticed that the Zigg Zagg example does in fact have this done in the Windows-friendly way, inside the function: https://ziglang.org/learn/samples/#zigg-zagg

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions