Adding compiler flags to c project build with zig (gtk4)

Hi,

i want to learn gtk4 using c, but i want to use zig as a build system.
On Windows i need to add -mwindows to the compiler so it won’t open a terminal window everytime the application starts.

the onliy thing i changed in the build.zig are these lines:

    const exe = b.addExecutable(.{
        .name = "clive",
        // In this case the main source file is merely a path, however, in more
        // complicated build scripts, this could be a generated file.
        .root_source_file = .{ .path = "src/main.c" },
        .target = target,
        .optimize = optimize,
    });

    exe.linkSystemLibrary("c");
    exe.linkSystemLibrary("gtk4");
    exe.linkSystemLibrary("libadwaita-1");

I know there is .addCSourceFile/.addCSourceFiles wich tage a &[_]const u8 with cflags. Do i need to use one of those?

I am using 0.11.0-dev.3859+88284c124 btw.

You want to set the subsystem to Windows:

exe.subsystem = .Windows;
3 Likes

I suggest leaving a console in the debug build, so that you can printf debug when necessary.

if (optimize != .Debug) exe.subsystem = .Windows;
2 Likes

That is a good idea thank you.