Skip to content

detect failure to link libc when there is a dependency on libc #2769

@dimenus

Description

@dimenus

using the following code in src/main.zig:

const std = @import("std");

pub usingnamespace @cImport({
    @cInclude("GLFW/glfw3.h");
});

pub fn main() anyerror!void {
    if (glfwInit() == 0) return error.GlfwInitFailed;
    std.debug.warn("All your base are belong to us.\n");
}

if I run
zig build-exe src/main.zig --library glfw --library-path /usr/lib

it fails with:

/home/ryan/repos/zgdb/src/main.zig:3:20: error: C import failed
pub usingnamespace @cImport({
                   ^
/home/ryan/repos/zgdb/src/main.zig:3:20: note: libc headers not available; compilation does not link against libc
pub usingnamespace @cImport({

but using zig build with this build.zig file causes SIGSEGV

const Builder = @import("std").build.Builder;

pub fn build(b: *Builder) void {
    const mode = b.standardReleaseOptions();
    const exe = b.addExecutable("zgdb", "src/main.zig");
    exe.setBuildMode(mode);
    exe.linkSystemLibrary("glfw");
    exe.setOutputDir(".");
    const run_cmd = exe.run();

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

    b.default_step.dependOn(&exe.step);
}

I recognize that the solution is to just include libc, but it seems like the behavior should be consistent, no?

edit (backtrace):

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x0000000000000000 in ?? ()

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions