Closed7

Zigのお勉強

s0ars0ar

hello-worldしろってことなんでする

mkdir hello-zig
❯ zig init-exe
❯ zig build run
s0ars0ar

README曰く、汝zig buildせよ

❯ zig build
/home/s0ar/projects/ziglings-exercises/build.zig:37:9: error: Sorry, it looks like your version of zig is too old. :-(
                                                              
                                                              Ziglings requires development build
                                                              
                                                              0.12.0-dev.2043
                                                              
                                                              or higher.
                                                              
                                                              Please download a development ("master") build from
                                                              
                                                              https://ziglang.org/download/
                                                              
                                                              
        @compileError(std.fmt.comptimePrint(error_message, .{min_zig}));
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/s0ar/projects/ziglings-exercises/build.zig:291:29: error: struct 'child_process.ChildProcess' has no member named 'run'
        const result = Child.run(.{
                       ~~~~~^~~~
/home/s0ar/.asdf/installs/zig/0.11.0/lib/std/child_process.zig:20:26: note: struct declared here
pub const ChildProcess = struct {
                         ^~~~~~

うーん草
最新の安定版じゃあかんらしい

s0ars0ar
❯ asdf list all zig
0.2.0
0.3.0
0.4.0
0.5.0
0.6.0
0.7.0
0.7.1
0.8.0
0.8.1
0.9.0
0.9.1
0.10.0
0.10.1
0.11.0
master

master入れる

❯ asdf install zig master
Downloading https://ziglang.org/builds/zig-linux-x86_64-0.12.0-dev.2543+9eda6ccef.tar.xz...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 45.9M  100 45.9M    0     0  17.0M      0  0:00:02  0:00:02 --:--:-- 17.0M

入った

❯ asdf list zig
 *0.11.0
  master

切り替える

❯ asdf global zig master

かわった~(布施明)

❯ zig version
0.12.0-dev.2543+9eda6ccef
s0ars0ar
❯ zig build              
         _       _ _
     ___(_) __ _| (_)_ __   __ _ ___
    |_  | |/ _' | | | '_ \ / _' / __|
     / /| | (_| | | | | | | (_| \__ \
    /___|_|\__, |_|_|_| |_|\__, |___/
           |___/           |___/

    "Look out! Broken programs below!"

Compiling: 001_hello.zig
error: the following command failed with 1 compilation errors:
/home/s0ar/.asdf/installs/zig/master/zig build-exe /home/s0ar/projects/ziglings-exercises/exercises/001_hello.zig --cache-dir /home/s0ar/projects/ziglings-exercises/zig-cache --listen=- 
/home/s0ar/.asdf/installs/zig/master/lib/std/start.zig:570:45: error: 'main' is not marked 'pub'
    switch (@typeInfo(@typeInfo(@TypeOf(root.main)).Fn.return_type.?)) {
                                        ~~~~^~~~~
exercises/001_hello.zig:19:1: note: declared here
fn main() void {
^~~~~~~~~~~~~~
/home/s0ar/.asdf/installs/zig/master/lib/std/start.zig:519:12: note: called from here
    return @call(.always_inline, callMain, .{});
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/s0ar/.asdf/installs/zig/master/lib/std/start.zig:469:36: note: called from here
    return initEventLoopAndCallMain();
           ~~~~~~~~~~~~~~~~~~~~~~~~^~
/home/s0ar/.asdf/installs/zig/master/lib/std/start.zig:425:17: note: called from here
    std.os.exit(@call(.always_inline, callMainWithArgs, .{ argc, argv, envp }));
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    _start: /home/s0ar/.asdf/installs/zig/master/lib/std/start.zig:338:40
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

Ziglings hint: DON'T PANIC!
Read the compiler messages above. (Something about 'main'?)
Open up the source file as noted below and read the comments.

(Hints like these will occasionally show up, but for the
most part, you'll be taking directions from the Zig
compiler itself.)

Edit exercises/001_hello.zig and run 'zig build' again.

力を示せ(修正しろ)と言われている

このスクラップは3ヶ月前にクローズされました