-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello World sample doesn't work in Windows #438
Comments
For anyone looking to copy-paste the working code.
|
jobansd
added a commit
to jobansd/www.ziglang.org
that referenced
this issue
Feb 21, 2025
Fixes: [issue ziglang#438](ziglang#438) - Hello World sample doesn't work in Windows [(Issue ziglang#438)](ziglang#438) - Declaring a const variable outside the main function fails on target x86_64-windows-gnu [(Issue #6845)](ziglang/zig#6845 (comment)) `getStdOut()` only works at runtime on Windows. This is resolved by moving the `getStdOut()` call into the main function's scope. Additionally, [`ziggzagg.zig`](https://ziglang.org/learn/samples/#zigg-zagg) example on the same page uses the correct approach.
jobansd
added a commit
to jobansd/www.ziglang.org
that referenced
this issue
Feb 21, 2025
Fixes: [issue ziglang#438](ziglang#438) - Hello World sample doesn't work in Windows [(Issue ziglang#438)](ziglang#438) - Declaring a const variable outside the main function fails on target x86_64-windows-gnu [(Issue #6845)](ziglang/zig#6845 (comment)) `getStdOut()` only works at runtime on Windows. This is resolved by moving the `getStdOut()` call into the main function's scope. Additionally, [`ziggzagg.zig`](https://ziglang.org/learn/samples/#zigg-zagg) example on the same page uses the correct approach.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The example given here: https://ziglang.org/learn/samples/#hello
As a beginner in zig, running it and seeing this mess wasn't fun:
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
The text was updated successfully, but these errors were encountered: