Hello,
I've tried to write a build.zig file to get rid of autotools of an old C project. While the project compiles fine, I have absolutely zero warnings when building my project with zig build. Can you tell me what I've done wrong with my build.zig file, please?
Removing the cache before compilation doesn't help.
I'm using Zig version 0.11.0-dev.3316+ec58b475b.
Here is a minimal working example:
main.c
#include <stdio.h>
int global = 1;
int main() {
int x;
int global = global;
printf("x = %d, and global = %d", x, global);
return 0;
}
build.zig
const std = @import("std");
const Build = std.build;
pub fn build(b: *Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "test",
.optimize = optimize,
.target = target,
});
exe.addCSourceFiles(&.{"main.c"}, &.{
"-std=c17",
"-Wpedantic",
"-Wall",
"-Wextra",
"-Wshadow",
});
exe.linkSystemLibrary("c");
b.installArtifact(exe);
const run = b.addRunArtifact(exe);
run.step.dependOn(b.getInstallStep());
}
Compiling with gcc -Wall -Wextra -Wpedantic -Wshadow main.c returns the following warnings:
main.c: In function ‘main’:
main.c:7:7: warning: declaration of ‘global’ shadows a global declaration [-Wshadow]
7 | int global = global;
| ^~~~~~
main.c:3:5: note: shadowed declaration is here
3 | int global = 1;
| ^~~~~~
main.c:8:3: warning: ‘x’ is used uninitialized [-Wuninitialized]
8 | printf("x = %d, and global = %d", x, global);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:6:7: note: ‘x’ was declared here
6 | int x;
| ^
Compiling with zig build produces nothing.
Best regards.