Skip to content

Linking with libc on Windows requires both wWinMain and WinMain #10460

Description

@revivalizer

Zig Version

0.10.0-dev.95+06286b05a

Steps to Reproduce

main.zig

const win32 = @import("std").os.windows;
const WINAPI = @import("std").os.windows.WINAPI;

pub export fn wWinMain(hInstance: win32.HINSTANCE, _: ?win32.HINSTANCE, pCmdLine: [*:0]u16, nCmdShow: c_int) callconv(WINAPI) c_int {
    _ = hInstance;
    _ = nCmdShow;
    _ = pCmdLine;

    return 0;
}

build.zig

    ...
    exe.linkLibC();
    exe.single_threaded = true;    
    ...

Expected Behavior

zig build success.

Actual Behavior

λ zig build
lld-link: error: undefined symbol: WinMain
>>> referenced by mingw32.lib(crt0_c.obj):(main)
error: LLDReportedFailure
libctest...The following command exited with error code 1:
C:\Users\ralph\Downloads\zig-windows-x86_64-0.10.0-dev.95+06286b05a\zig.exe build-exe C:\code\libctest\src\main.zig -lc --cache-dir C:\code\libctest\zig-cache --global-cache-dir C:\Users\ralph\AppData\Local\zig --name libctest -fsingle-threaded --enable-cache
error: the following build command failed with exit code 1:
C:\code\libctest\zig-cache\o\9f6d466e1acf870ea83a5add8bf20452\build.exe C:\Users\ralph\Downloads\zig-windows-x86_64-0.10.0-dev.95+06286b05a\zig.exe C:\code\libctest C:\code\libctest\zig-cache C:\Users\ralph\AppData\Local\zig

Note that zig does not allow me to just use WinMain:

λ zig build
C:\Users\ralph\Downloads\zig-windows-x86_64-0.10.0-dev.95+06286b05a\lib\std\start.zig:61:21: error: WinMain not supported; declare wWinMain or main instead
                    @compileError("WinMain not supported; declare wWinMain or main instead");
                    ^
libctest...The following command exited with error code 1:
C:\Users\ralph\Downloads\zig-windows-x86_64-0.10.0-dev.95+06286b05a\zig.exe build-exe C:\code\libctest\src\main.zig -lc --cache-dir C:\code\libctest\zig-cache --global-cache-dir C:\Users\ralph\AppData\Local\zig --name libctest -fsingle-threaded --enable-cache
error: the following build command failed with exit code 1:
C:\code\libctest\zig-cache\o\9f6d466e1acf870ea83a5add8bf20452\build.exe C:\Users\ralph\Downloads\zig-windows-x86_64-0.10.0-dev.95+06286b05a\zig.exe C:\code\libctest C:\code\libctest\zig-cache C:\Users\ralph\AppData\Local\zig

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavioros-windowsMicrosoft Windowsstandard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions