IOKit/IOKitLib.h errors #289

Open
opened 2026-02-12 12:34:15 +01:00 by utox39 · 0 comments

Zig fail to build when including IOKit/IOKitLib.h.
Even the addTranslateC approach does not work.

  • Zig version: 0.16.0-dev.2535+b5bd49460
  • macOS version: macOS 26.2

It works with zig v0.15.2

main.zig:

const std = @import("std");
const c = @cImport(@cInclude("IOKit/IOKitLib.h"));

pub fn main() !void {
    const service = c.IOServiceGetMatchingService(c.kIOMasterPortDefault, c.IOServiceNameMatching("pmgr"));
    if (service == c.FALSE) return error.NoMatchingService;
    defer _ = c.IOObjectRelease(service);
}

build.zig:

const std = @import("std");

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

    const exe = b.addExecutable(.{
        .name = "zig_0_16_iokit_error",
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/main.zig"),
            .target = target,
            .optimize = optimize,
            .imports = &.{},
        }),
    });

    exe.root_module.linkFramework("IOKit", .{ .needed = true });

    b.installArtifact(exe);

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

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

    run_cmd.step.dependOn(b.getInstallStep());

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

    const exe_tests = b.addTest(.{
        .root_module = exe.root_module,
    });

    const run_exe_tests = b.addRunArtifact(exe_tests);

    const test_step = b.step("test", "Run tests");
    test_step.dependOn(&run_exe_tests.step);
}

Errors:

$ zig build run --summary all

run
└─ run exe zig_0_16_iokit_error
   └─ compile exe zig_0_16_iokit_error Debug native 5 errors
src/main.zig:2:11: error: C import failed
const c = @cImport(@cInclude("IOKit/IOKitLib.h"));
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    callMainWithArgs [inlined]: /Users/utox/.asdf/installs/zig/master/lib/std/start.zig:629:12
    main: /Users/utox/.asdf/installs/zig/master/lib/std/start.zig:654:28
    2 reference(s) hidden; use '-freference-trace=4' to see all references
error: translation failure
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ConditionalMacros.h:193:5: error: unknown compiler
   #error unknown compiler
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/MacTypes.h:181:41: error: typedef redefinition with different types ('wide' (aka 'struct wide') vs 'int64_t' (aka 'long long'))
typedef wide                            SInt64;
                                        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/MacTypes.h:182:41: error: typedef redefinition with different types ('UnsignedWide' (aka 'struct UnsignedWide') vs 'uint64_t' (aka 'unsigned long long'))
typedef UnsignedWide                    UInt64;
                                        ^
error: 5 compilation errors
failed command: /Users/utox/.asdf/installs/zig/master/zig build-exe -ODebug -Mroot=/Users/utox/Developer/test/zig-0-16-iokit-error/src/main.zig -needed_framework IOKit --cache-dir .zig-cache --global-cache-dir /Users/utox/.cache/zig --name zig_0_16_iokit_error --zig-lib-dir /Users/utox/.asdf/installs/zig/master/lib/ --listen=-

Build Summary: 0/5 steps succeeded (1 failed)
run transitive failure
└─ run exe zig_0_16_iokit_error transitive failure
   ├─ compile exe zig_0_16_iokit_error Debug native 5 errors
   └─ install transitive failure
      └─ install zig_0_16_iokit_error transitive failure
         └─ compile exe zig_0_16_iokit_error Debug native (reused)

error: the following build command failed with exit code 1:
.zig-cache/o/1f937a0ebeee4d51525a37318e309bfc/build /Users/utox/.asdf/installs/zig/master/zig /Users/utox/.asdf/installs/zig/master/lib /Users/utox/Developer/test/zig-0-16-iokit-error .zig-cache /Users/utox/.cache/zig --seed 0xc2fc5043 -Z320527c64f93b445 run --summary all
Zig fail to build when including `IOKit/IOKitLib.h`. Even the addTranslateC approach does not work. - Zig version: `0.16.0-dev.2535+b5bd49460` - macOS version: `macOS 26.2` It works with `zig v0.15.2` main.zig: ```zig const std = @import("std"); const c = @cImport(@cInclude("IOKit/IOKitLib.h")); pub fn main() !void { const service = c.IOServiceGetMatchingService(c.kIOMasterPortDefault, c.IOServiceNameMatching("pmgr")); if (service == c.FALSE) return error.NoMatchingService; defer _ = c.IOObjectRelease(service); } ``` build.zig: ```zig const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const exe = b.addExecutable(.{ .name = "zig_0_16_iokit_error", .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .imports = &.{}, }), }); exe.root_module.linkFramework("IOKit", .{ .needed = true }); b.installArtifact(exe); const run_step = b.step("run", "Run the app"); const run_cmd = b.addRunArtifact(exe); run_step.dependOn(&run_cmd.step); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); } const exe_tests = b.addTest(.{ .root_module = exe.root_module, }); const run_exe_tests = b.addRunArtifact(exe_tests); const test_step = b.step("test", "Run tests"); test_step.dependOn(&run_exe_tests.step); } ``` Errors: ```bash $ zig build run --summary all run └─ run exe zig_0_16_iokit_error └─ compile exe zig_0_16_iokit_error Debug native 5 errors src/main.zig:2:11: error: C import failed const c = @cImport(@cInclude("IOKit/IOKitLib.h")); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ referenced by: callMainWithArgs [inlined]: /Users/utox/.asdf/installs/zig/master/lib/std/start.zig:629:12 main: /Users/utox/.asdf/installs/zig/master/lib/std/start.zig:654:28 2 reference(s) hidden; use '-freference-trace=4' to see all references error: translation failure /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ConditionalMacros.h:193:5: error: unknown compiler #error unknown compiler ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/MacTypes.h:181:41: error: typedef redefinition with different types ('wide' (aka 'struct wide') vs 'int64_t' (aka 'long long')) typedef wide SInt64; ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/MacTypes.h:182:41: error: typedef redefinition with different types ('UnsignedWide' (aka 'struct UnsignedWide') vs 'uint64_t' (aka 'unsigned long long')) typedef UnsignedWide UInt64; ^ error: 5 compilation errors failed command: /Users/utox/.asdf/installs/zig/master/zig build-exe -ODebug -Mroot=/Users/utox/Developer/test/zig-0-16-iokit-error/src/main.zig -needed_framework IOKit --cache-dir .zig-cache --global-cache-dir /Users/utox/.cache/zig --name zig_0_16_iokit_error --zig-lib-dir /Users/utox/.asdf/installs/zig/master/lib/ --listen=- Build Summary: 0/5 steps succeeded (1 failed) run transitive failure └─ run exe zig_0_16_iokit_error transitive failure ├─ compile exe zig_0_16_iokit_error Debug native 5 errors └─ install transitive failure └─ install zig_0_16_iokit_error transitive failure └─ compile exe zig_0_16_iokit_error Debug native (reused) error: the following build command failed with exit code 1: .zig-cache/o/1f937a0ebeee4d51525a37318e309bfc/build /Users/utox/.asdf/installs/zig/master/zig /Users/utox/.asdf/installs/zig/master/lib /Users/utox/Developer/test/zig-0-16-iokit-error .zig-cache /Users/utox/.cache/zig --seed 0xc2fc5043 -Z320527c64f93b445 run --summary all ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ziglang/translate-c#289
No description provided.