Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit code 5 on Windows compiling external C API #13022

Closed
nekrondev opened this issue Sep 30, 2022 · 7 comments
Closed

Exit code 5 on Windows compiling external C API #13022

nekrondev opened this issue Sep 30, 2022 · 7 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@nekrondev
Copy link

nekrondev commented Sep 30, 2022

Zig Version

0.10.0-dev.4197+9a2f17f9f

Steps to Reproduce

  1. zig build on Windows 10 OS the following program

build.zig:

const std = @import("std");

pub fn build(b: *std.build.Builder) !void {
    const mode = b.standardReleaseOptions();
    const target = b.standardTargetOptions(.{});

    const service = b.addExecutable("crashfive", "src/main.zig");
    service.linkSystemLibrary("c");
    service.setBuildMode(mode);
    service.setTarget(target);

    // build and install the worker exe
    service.install();
}

main.zig:

const std = @import("std");

/// use Windows c-api signal function
/// build.zig must include C lib (exe.linkSystemLibrary("c");)
pub extern "c" fn signal(sig: c_int, handler: fn (c_int, c_int) callconv(.C) void) *anyopaque;

/// interruptFn used to catch CTRL-C on Windows OS only
/// see https://docs.microsoft.com/en-us/previous-versions/xdkz3x12(v=vs.140)
fn interruptFn(_: c_int, _: c_int) callconv(.C) void {}

/// main
pub fn main() void {
    _ = signal(std.c.SIG.INT, interruptFn);
}

Expected Behavior

Executable binary will be build without issues (this was working back when I was using zig in July 2022).

Actual Behavior

PS C:\Setup\zig\exitfive> zig build
error: crashfive...
error: The following command exited with error code 5:
C:\users\hbe\zig\zig.exe build-exe C:\Setup\zig\exitfive\src\main.zig -lc --cache-dir C:\Setup\zig\exitfive\zig-cache --global-cache-dir C:\Users\HBE\AppData\Local\zig --name crashfive --enable-cache 
error: the following build command failed with exit code 5:
C:\Setup\zig\exitfive\zig-cache\o\37906a44628083d55fdf5825df7c2698\build.exe C:\users\hbe\zig\zig.exe C:\Setup\zig\exitfive C:\Setup\zig\exitfive\zig-cache C:\Users\HBE\AppData\Local\zig
@nekrondev nekrondev added the bug Observed behavior contradicts documented or intended behavior label Sep 30, 2022
@nektro
Copy link
Contributor

nektro commented Sep 30, 2022

-pub extern "c" fn signal(sig: c_int, handler: fn (c_int, c_int) callconv(.C) void) *anyopaque;
+pub extern "c" fn signal(sig: c_int, handler: *const fn (c_int, c_int) callconv(.C) void) *anyopaque;

@nektro
Copy link
Contributor

nektro commented Sep 30, 2022

-fn interruptFn(_: c_int, _: c_int) callconv(.C) void {}
+export fn interruptFn(_: c_int, _: c_int) void {}

@nekrondev
Copy link
Author

@nektro Hey that was amazingly fast! I'll give it a try and many thanks for your superfast help!!

Yea it works... issue solved within <<60s ... wooowww!!

@Vexu
Copy link
Member

Vexu commented Sep 30, 2022

That example should not compile.

@Vexu Vexu reopened this Sep 30, 2022
@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Sep 30, 2022
@Vexu Vexu added this to the 0.10.0 milestone Sep 30, 2022
@nekrondev
Copy link
Author

@Vexu The original source (without @nektro changes) did not compile on Windows but nor did print an error what's wrong (just exit code 5).

@nektro
Copy link
Contributor

nektro commented Sep 30, 2022

yeah the issue should stay open since it should report a compile error instead of crash. i was only providing guidance on a workaround @nekrondev :)

@nekrondev
Copy link
Author

Yep.. ACK on that (error messages are always helpful but great community is the best)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

3 participants