#Compile in a main.c

1 messages · Page 1 of 1 (latest)

errant spade
#

Just following along some tutorials for C and doing the zig (v 0.15.2) equivalents, but i'd like to use zig for compiling the C so i can learn more about the build system too.

Have the following:

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
      .name = "lel",
      .module = b.createModule(.{   <== Problem here
        .target = target,
        .optimize = optimize,
        .link_libc = true,
      }),
    });
    exe.root_module.addCSourceFiles(.{
      //.flags = &.{ ... },
      .files = &.{ "main.c" },
    });
    exe.linkLibC();

    b.installArtifact(exe);

    const run_cmd = b.addRunArtifact(exe);
    run_cmd.step.dependOn(b.getInstallStep());

    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);
}

But it complains on the .module = b.createModule(... line with:

      .module = b.createModule(.{

Any pointers appreciated

stray anchor
#

It's simpler than that now

    const exe = b.addExecutable(.{
        .name = "main",
        .root_module = b.createModule(.{
            .target = target,
            .optimize = optimize,
            .link_libc = true,
        }),
    });
    exe.addCSourceFiles(.{
        .files = &.{
            "main.c",
        },
    });
    b.installArtifact(exe);