Skip to content

Running Hello Zig Build, error: no field named 'root_source_file' in struct 'Build.ExecutableOptions' #325

@qrhfz

Description

@qrhfz

when running example given in https://zig.guide/0.12/build-system/zig-build

build.zig:6:10: error: no field named 'root_source_file' in struct 'Build.ExecutableOptions'
        .root_source_file = .{ .path = "src/main.zig" },
         ^~~~~~~~~~~~~~~~
/usr/lib/zig/std/Build.zig:771:31: note: struct declared here
pub const ExecutableOptions = struct {
                              ^~~~~~
referenced by:
    runBuild__anon_23457: /usr/lib/zig/std/Build.zig:2214:33
    main: /usr/lib/zig/compiler/build_runner.zig:366:29
    5 reference(s) hidden; use '-freference-trace=7' to see all references
	

after looking at zig's official docs i fixed it using:

diff --git a/build.zig b/build.zig
index 4b4bd09..576daad 100644
--- a/build.zig
+++ b/build.zig
@@ -3,9 +3,11 @@ const std = @import("std");
 pub fn build(b: *std.Build) void {
     const exe = b.addExecutable(.{
         .name = "hello",
-        .root_source_file = .{ .path = "main.zig" },
-        .target = b.standardTargetOptions(.{}),
-        .optimize = b.standardOptimizeOption(.{}),
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("main.zig"),
+            .target = b.standardTargetOptions(.{}),
+            .optimize = b.standardOptimizeOption(.{}),
+        }),
     });
 
     b.installArtifact(exe);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions