~andrewrk/ziglang

1

How to build a ReleaseSmall hello world binary?

Details
Message ID
<CAPxz1+YEUxxoROF9wAEQQNPk=xsno1JqNN+D+fzzGmOTsc-M1w@mail.gmail.com>
DKIM signature
missing
Download raw message
Hello,

I am trying out Zig for the first time.  It is exciting to discover a
modern language with first-class support for no standard library.

I was trying to build a small hello world program following the
(apparently now outdated) instructions here:

https://drewdevault.com/2020/01/04/Slow.html#testzig

I figured out that the command should probably be changed to the following:

./zig build-exe -O ReleaseSmall -fstrip hello.zig

However, this generates a compile time error:

hello.zig:4:43: error: expected error union type, found 'fs.file.File'
    const stdout  =  try  std.io.getStdOut();

Can anyone provide updated source code so that the example will compile?

For reference, here is the original (outdated) source code:

const std = @import("std");
pub fn main() !void {
    const stdout = try std.io.getStdOut();
    try stdout.write("hello world\n");
}

Thank you!

Parke
Details
Message ID
<f3736c4d-238a-089d-63a9-0ac95b77ce8a@ziglang.org>
In-Reply-To
<CAPxz1+YEUxxoROF9wAEQQNPk=xsno1JqNN+D+fzzGmOTsc-M1w@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
On 8/21/23 15:22, Parke wrote:
> Hello,
> 
> I am trying out Zig for the first time.  It is exciting to discover a
> modern language with first-class support for no standard library.
> 
> I was trying to build a small hello world program following the
> (apparently now outdated) instructions here:
> 
> https://drewdevault.com/2020/01/04/Slow.html#testzig
> 
> I figured out that the command should probably be changed to the following:
> 
> ./zig build-exe -O ReleaseSmall -fstrip hello.zig
> 
> However, this generates a compile time error:
> 
> hello.zig:4:43: error: expected error union type, found 'fs.file.File'
>      const stdout  =  try  std.io.getStdOut();
> 
> Can anyone provide updated source code so that the example will compile?

1. getStdOut no longer fails; remove `try`
2. change `write` to `writeAll`

I updated the sample below for you:

> 
> For reference, here is the original (outdated) source code:
> 

const std = @import("std");

pub fn main() !void {
     const stdout = std.io.getStdOut();
     try stdout.writeAll("hello world\n");
}

> 
> Thank you!
> 
> Parke

Happy hacking!
Andrew
Reply to thread Export thread (mbox)