Skip to content

README.md example does not compile (macOS) #22

@Zorgatone

Description

@Zorgatone

The example I replicated from the README.md does not compile (tested with Zig 0.15.1, zopengl and zglfw).

I'm on macOS Tahoe 26.0.1 (25A362) on Apple silicon.

Zig env:

.{
    .zig_exe = "/Users/zorgatone/.local/share/zigup/0.15.2/files/zig",
    .lib_dir = "/Users/zorgatone/.local/share/zigup/0.15.2/files/lib",
    .std_dir = "/Users/zorgatone/.local/share/zigup/0.15.2/files/lib/std",
    .global_cache_dir = "/Users/zorgatone/.cache/zig",
    .version = "0.15.2",
    .target = "aarch64-macos.26.0.1...26.0.1-none",
    .env = .{
        .ZIG_GLOBAL_CACHE_DIR = null,
        .ZIG_LOCAL_CACHE_DIR = null,
        .ZIG_LIB_DIR = null,
        .ZIG_LIBC = null,
        .ZIG_BUILD_RUNNER = null,
        .ZIG_VERBOSE_LINK = null,
        .ZIG_VERBOSE_CC = null,
        .ZIG_BTRFS_WORKAROUND = null,
        .ZIG_DEBUG_CMD = null,
        .CC = null,
        .NO_COLOR = null,
        .CLICOLOR_FORCE = null,
        .XDG_CACHE_HOME = null,
        .HOME = "/Users/zorgatone",
    },
}
const std = @import("std");

const zglfw = @import("zglfw");
const zopengl = @import("zopengl");

fn getProcAddress(procName: [:0]const u8) callconv(.c) ?*const anyopaque {
    return zglfw.getProcAddress(procName);
}

pub fn main() !void {
    try zglfw.init();
    defer zglfw.terminate();

    const window = try zglfw.createWindow(600, 600, "Hello, World!", null);
    defer zglfw.destroyWindow(window);

    // setup your graphics context here
    try zopengl.loadCoreProfile(getProcAddress, 4, 0);
    const gl = zopengl.bindings;

    while (!window.shouldClose()) {
        zglfw.pollEvents();

        // render your things here
        gl.clearBufferfv(gl.COLOR, 0, &.{ 0.2, 0.4, 0.8, 1.0 });

        window.swapBuffers();
    }
}

When compiling this is the error I get

> zig build run --summary all
run
└─ run exe zig_gl_test
   └─ compile exe zig_gl_test Debug native 1 errors
src/main.zig:6:19: error: parameter of type '[:0]const u8' not allowed in function with calling convention 'aarch64_aapcs_darwin'
fn getProcAddress(procName: [:0]const u8) callconv(.c) ?*const anyopaque {
                  ^~~~~~~~~~~~~~~~~~~~~~
src/main.zig:6:19: note: slices have no guaranteed in-memory representation
referenced by:
    main: src/main.zig:18:33
    callMain [inlined]: /Users/zorgatone/.local/share/zigup/0.15.2/files/lib/std/start.zig:627:37
    callMainWithArgs [inlined]: /Users/zorgatone/.local/share/zigup/0.15.2/files/lib/std/start.zig:587:20
    main: /Users/zorgatone/.local/share/zigup/0.15.2/files/lib/std/start.zig:602:28
    1 reference(s) hidden; use '-freference-trace=5' to see all references
error: the following command failed with 1 compilation errors:
/Users/zorgatone/.local/share/zigup/0.15.2/files/zig build-exe .zig-cache/o/602e49ce94b3d33c6dd3489304db1363/libglfw.a -ODebug -I .zig-cache/o/3f07ff85abbb450996ed5c70e55044de --dep zglfw --dep zopengl -Mroot=/Users/zorgatone/source/repos/Personal/zig/opengl/zig-gl-test/src/main.zig -I /Users/zorgatone/.cache/zig/p/zglfw-0.10.0-dev-zgVDNPKyIQCBi-wv_vxkvIQq1u0bP4D56Wszx_2mszc7/libs/glfw/include --dep zglfw_options -Mzglfw=/Users/zorgatone/.cache/zig/p/zglfw-0.10.0-dev-zgVDNPKyIQCBi-wv_vxkvIQq1u0bP4D56Wszx_2mszc7/src/zglfw.zig -Mzopengl=/Users/zorgatone/.cache/zig/p/zopengl-0.6.0-dev-5-tnz9g8CQBbUiEouos-P6EE87Gf0GWUzsMh9XDvAtLP/src/zopengl.zig -Mzglfw_options=.zig-cache/c/a06fb2bc7e5ab1184316219d8a865f54/options.zig -lobjc -framework IOKit -framework CoreFoundation -framework Metal -framework AppKit -framework CoreServices -framework CoreGraphics -framework Foundation -lc --cache-dir .zig-cache --global-cache-dir /Users/zorgatone/.cache/zig --name zig_gl_test --zig-lib-dir /Users/zorgatone/.local/share/zigup/0.15.2/files/lib/ --listen=-

Build Summary: 3/8 steps succeeded; 1 failed
run transitive failure
└─ run exe zig_gl_test transitive failure
   ├─ compile exe zig_gl_test Debug native 1 errors
   │  ├─ WriteFile  cached
   │  ├─ compile lib glfw Debug native cached 54ms MaxRSS:31M
   │  ├─ compile lib glfw Debug native (reused)
   │  └─ options cached
   └─ install transitive failure
      └─ install zig_gl_test transitive failure
         └─ compile exe zig_gl_test Debug native (+4 more reused dependencies)

error: the following build command failed with exit code 1:
.zig-cache/o/7a0a3ae308cea8cf283d34ecd276696c/build /Users/zorgatone/.local/share/zigup/0.15.2/files/zig /Users/zorgatone/.local/share/zigup/0.15.2/files/lib /Users/zorgatone/source/repos/Personal/zig/opengl/zig-gl-test .zig-cache /Users/zorgatone/.cache/zig --seed 0xf528c26c -Z26de89bbf72dab5b run --summary all

So I change the getProcAddress function signature:

const std = @import("std");

const zglfw = @import("zglfw");
const zopengl = @import("zopengl");

fn getProcAddress(procName: [*:0]const u8) callconv(.c) ?*const anyopaque {
    return zglfw.getProcAddress(procName);
}

pub fn main() !void {
    try zglfw.init();
    defer zglfw.terminate();

    const window = try zglfw.createWindow(600, 600, "Hello, World!", null);
    defer zglfw.destroyWindow(window);

    // setup your graphics context here
    try zopengl.loadCoreProfile(getProcAddress, 4, 0);
    const gl = zopengl.bindings;

    while (!window.shouldClose()) {
        zglfw.pollEvents();

        // render your things here
        gl.clearBufferfv(gl.COLOR, 0, &.{ 0.2, 0.4, 0.8, 1.0 });

        window.swapBuffers();
    }
}

I still get more errors:

> zig build run --summary all
run
└─ run exe zig_gl_test
   └─ compile exe zig_gl_test Debug native 1 errors
src/main.zig:25:41: error: type 'f32' does not support array initialization syntax
        gl.clearBufferfv(gl.COLOR, 0, &.{ 0.2, 0.4, 0.8, 1.0 });
                                       ~^~~~~~~~~~~~~~~~~~~~~~
referenced by:
    callMain [inlined]: /Users/zorgatone/.local/share/zigup/0.15.2/files/lib/std/start.zig:627:37
    callMainWithArgs [inlined]: /Users/zorgatone/.local/share/zigup/0.15.2/files/lib/std/start.zig:587:20
    main: /Users/zorgatone/.local/share/zigup/0.15.2/files/lib/std/start.zig:602:28
    1 reference(s) hidden; use '-freference-trace=4' to see all references
error: the following command failed with 1 compilation errors:
/Users/zorgatone/.local/share/zigup/0.15.2/files/zig build-exe .zig-cache/o/602e49ce94b3d33c6dd3489304db1363/libglfw.a -ODebug -I .zig-cache/o/3f07ff85abbb450996ed5c70e55044de --dep zglfw --dep zopengl -Mroot=/Users/zorgatone/source/repos/Personal/zig/opengl/zig-gl-test/src/main.zig -I /Users/zorgatone/.cache/zig/p/zglfw-0.10.0-dev-zgVDNPKyIQCBi-wv_vxkvIQq1u0bP4D56Wszx_2mszc7/libs/glfw/include --dep zglfw_options -Mzglfw=/Users/zorgatone/.cache/zig/p/zglfw-0.10.0-dev-zgVDNPKyIQCBi-wv_vxkvIQq1u0bP4D56Wszx_2mszc7/src/zglfw.zig -Mzopengl=/Users/zorgatone/.cache/zig/p/zopengl-0.6.0-dev-5-tnz9g8CQBbUiEouos-P6EE87Gf0GWUzsMh9XDvAtLP/src/zopengl.zig -Mzglfw_options=.zig-cache/c/a06fb2bc7e5ab1184316219d8a865f54/options.zig -lobjc -framework IOKit -framework CoreFoundation -framework Metal -framework AppKit -framework CoreServices -framework CoreGraphics -framework Foundation -lc --cache-dir .zig-cache --global-cache-dir /Users/zorgatone/.cache/zig --name zig_gl_test --zig-lib-dir /Users/zorgatone/.local/share/zigup/0.15.2/files/lib/ --listen=-

Build Summary: 3/8 steps succeeded; 1 failed
run transitive failure
└─ run exe zig_gl_test transitive failure
   ├─ compile exe zig_gl_test Debug native 1 errors
   │  ├─ WriteFile  cached
   │  ├─ compile lib glfw Debug native cached 57ms MaxRSS:31M
   │  ├─ compile lib glfw Debug native (reused)
   │  └─ options cached
   └─ install transitive failure
      └─ install zig_gl_test transitive failure
         └─ compile exe zig_gl_test Debug native (+4 more reused dependencies)

error: the following build command failed with exit code 1:
.zig-cache/o/7a0a3ae308cea8cf283d34ecd276696c/build /Users/zorgatone/.local/share/zigup/0.15.2/files/zig /Users/zorgatone/.local/share/zigup/0.15.2/files/lib /Users/zorgatone/source/repos/Personal/zig/opengl/zig-gl-test .zig-cache /Users/zorgatone/.cache/zig --seed 0xe9fafe8a -Z433931bff8d17d36 run --summary all

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions