Skip to content

MissingMainEntrypoint on macOS during release builds #8552

Closed

Description

@cryptocode

I have a project with a dependency on a C file. This works fine with plain zig build, but with -Drelease-safe=true the build results in:

zig build-exe src/main.zig -cflags -std=c99 -- deps/linenoise.c -OReleaseSafe --cache-dir zig-cache --global-cache-dir /Users/user/.cache/zig --name app -I deps --enable-cache

LLVM Emit Object...
error: MissingMainEntrypoint

app...The following command exited with error code 1:
zig build-exe src/main.zig -cflags -std=c99 -- deps/linenoise.c -OReleaseSafe --cache-dir zig-cache --global-cache-dir /Users/user/.cache/zig --name app -I deps --enable-cache

error: the following build command failed with exit code 1:
zig-cache/o/fdb0418b57bb58f267a95d7e400a17da/build zig /Users/user/app zig-cache /Users/user/.cache/zig --verbose -Drelease-safe=true

The zig binary is d1a41fe on macOS x64.

The object files are of type LLVM bitcode, wrapper x86_64 after the error.

Release builds work fine if I remove the dependency on the C file.

Here's the build file:

const std = @import("std");

pub fn build(b: *std.build.Builder) void {
    const target = b.standardTargetOptions(.{});
    const mode = b.standardReleaseOptions();

    const exe = b.addExecutable("app", "src/main.zig");
    if (!target.isWindows()) {
        exe.addCSourceFile("deps/linenoise.c", &[_][]const u8{"-std=c99"});
        exe.addIncludeDir("deps");
    }    
    exe.setTarget(target);
    exe.setBuildMode(mode);
    exe.install();

    const run_cmd = exe.run();
    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);
}

Activity

  1. added
    arch-x86_64
    stage1
    bug
    on Apr 19, 2021
  2. kubkon commented on Apr 19, 2021

    @kubkon
    Member

    Different linkers, but I wonder if the root cause is in any way related to #8531.

  3. added this to the 0.8.0 milestone on Apr 19, 2021
  4. modified the milestones: 0.8.0, 0.9.0 on May 18, 2021
  5. modified the milestones: 0.9.0, 0.10.0 on May 19, 2021
  6. mikdusan commented on Jan 1, 2023

    @mikdusan
    Member

    Is this still a bug? I have no issue combining a .c on a zig build-exe main.zig ... command line; tried debug + all 3 release modes.

  7. kubkon commented on Jan 1, 2023

    @kubkon
    Member

    Is this still a bug? I have no issue combining a .c on a zig build-exe main.zig ... command line; tried debug + all 3 release modes.

    It's a missing feature tracked by #8680 I believe. Given that we currently have LTO disabled when targeting macOS, if shouldn't pop up unless someone explicitly passes an LLVM bitcode file as input to Zig.

  8. modified the milestones: 0.12.0, 0.11.0 on Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-x86_64buglinkingos-macosstage1

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions