exporting a C main function regressed
Zig Version
0.10.0-dev.3665+9cf667a21
Steps to Reproduce
const string = [*:0]const u8;
const stringarray = [*:null]const ?string;
pub export fn main(argc: c_int, argv: stringarray) c_int {
_ = argc;
_ = argv;
return 0;
}
Expected Behavior
successful compile and run
Actual Behavior
/home/meghan/src/zig/lib/std/start.zig:571:17: error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
@compileError(bad_main_ret);
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/meghan/src/zig/lib/std/start.zig:510:12: note: called from here
return @call(.{ .modifier = .always_inline }, callMain, .{});
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/meghan/src/zig/lib/std/start.zig:460:36: note: called from here
return initEventLoopAndCallMain();
~~~~~~~~~~~~~~~~~~~~~~~~^~
/home/meghan/src/zig/lib/std/start.zig:424:17: note: called from here
std.os.exit(@call(.{ .modifier = .always_inline }, callMainWithArgs, .{ argc, argv, envp }));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This doesn't seem to work with stage1 either:
$ zig run a.zig -fstage1
./lib/std/start.zig:571:17: error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
@compileError(bad_main_ret);
^
yeah there seems to be odd conditions where it skips the check, but the minimal repro caught it so i thought it might be a regression
https://github.com/nektro/mount.ufs/blob/master/src/main.zig#L20 builds fine with stage1 even though i use the c_int main return here
it already works. use export
sorry, I got tricked by #20645, this is indeed a regression.
Please remember to fill out Steps To Reproduce. If you had, I would have noticed that you omitted -lc and then we wouldn't have wasted everybody's time.
This is working as designed. You must use -lc if you want to export a main that libc calls.