I am trying to follow this tutorial. I am running on MacOS Catalina, 10.15.3 , on a 13" Macbook pro from 2016. I downloaded the latest release from here for Mac. I unzipped the file, and moved the zig executable (but not the rest of the contents of the folder) to usr/local/bin so I could call it from anywhere. Now, regardless of where I run it, I can call zig version
and get the output 0.6.0+352976ed2
as expected. However, whenever I try something like zig run main.zig
or zig build main.zig
it just freezes and does nothing.
Now the tutorial does say that it doesn't support zig 0.6.0. But I was assuming that this would still work, and the tutorial was referring more to things like the way to print being changed when it said it doesn't support 0.6.0. Obviously this could be an incorrect assumption, but I don't know why this wouldn't work. And as zig is young, has a shortage of getting started tutorials so I don't know where else to look.
I have gotten zig 0.6.0 to work with homebrew before, but as I am potentially looking at contributing or trying experimental branches of the compiler down the line, I want to be able to run an arbitrary zig executable.
I was able to fix my problem. First I removed zig from usr/local/bin
, and any other files associated with the original download. Then instead of downloading the master release, I downloaded the 0.6.0 release for mac. I unzipped it. I tried compiling with it directly from there, and it worked. However when I moved it to usr/local/bin
it gave me the error,
Unable to find zig lib directory
so clearly the executable needed to be with the rest of the folder's contents, where I replaced the executable.
I created a new directory in my home directory that I named tools
. I moved the unzipped folder (called zig-macos-x86_64-0.6.0) into the tools
directory. Then (from my home directory) I created a symlink to the binary in my bin using this command.
ln -s tools/zig-macos-x86_64-0.6.0/zig ../../usr/local/bin/zig
I quit and restarted terminal. Now zig version
produces 0.6.0
and when compiling the program main.zig
,
const std = @import("std");
pub fn main() void {
std.debug.warn("Hello, {}!\n", .{"World"});
}
using the command zig run main.zig
I get the proper output of
Hello, World!