Skip to content

root source file has no member called 'main' when WinMain is defined. #3712

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

Closed
JesseRMeyer opened this issue Nov 18, 2019 · 6 comments · Fixed by #3733
Closed

root source file has no member called 'main' when WinMain is defined. #3712

JesseRMeyer opened this issue Nov 18, 2019 · 6 comments · Fixed by #3733
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@JesseRMeyer
Copy link

JesseRMeyer commented Nov 18, 2019

On Zig 0.5.0+a11da3773.

zig build-exe ../src/test.zig --subsystem windows
C:\dev\Zig\lib\zig\std\special\start.zig:227:35: error: root source file has no member called 'main'

usingnamespace @import("std").os.windows;

extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) c_int;

export stdcallcc fn WinMain(hInstance: ?HINSTANCE, hPrevInstance: ?HINSTANCE, lpCmdLine: ?LPWSTR, nShowCmd: INT) INT {
    _ = MessageBoxA(null, c"hello", c"world", 0);

    return 0;
}

Interestingly, the error is only prompted if stdcallcc is not provided, but it's required otherwise the parameters are not accessible to the function as the calling convention is not observed.

If main() is defined then WinMain() is never called.

@JesseRMeyer
Copy link
Author

JesseRMeyer commented Nov 20, 2019

To my knowledge this is a show stopper for Windows development for any instance where WinMain's function parameters are required.

@andrewrk andrewrk added this to the 0.6.0 milestone Nov 27, 2019
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Nov 27, 2019
@JesseRMeyer
Copy link
Author

This problem continues to persist in build 0.5.0+008e42f48 (12/07/2019).

Minimal repo.

usingnamespace @import("std").os.windows;

export stdcallcc fn WinMain(hInstance: ?HINSTANCE, hPrevInstance: ?HINSTANCE, lpCmdLine: ?LPWSTR, nShowCmd: INT) INT {
    return 0;
}

@Vexu
Copy link
Member

Vexu commented Dec 7, 2019

WinMain has to be pub.

@JesseRMeyer
Copy link
Author

I thought exporting implied the function was public? Where are the rules on that? Easy and confusing situation to get oneself in either case, so I think Zig would warn more helpfully in this situation, which I'm sure is going to continue to happen as Zig grows more alluring to win32 devs.

@andrewrk
Copy link
Member

andrewrk commented Dec 7, 2019

I agree it's a bit counter intuitive at the moment. This area of the language is unstable.

#1717 is accepted. That will probably encourage reconsidering #181, so that something as common as defining a function is not tedious. There is also #661.

export is technically not needed. One could do this (hypothetically with above 3 things implemented):

let foo = fn (hInstance: ?HINSTANCE, hPrevInstance: ?HINSTANCE, lpCmdLine: ?LPWSTR, nShowCmd: INT) callconv(.stdcallcc) INT {
    return 0;
}

comptime {
    @export("WinMain", foo, .Strong);
}

It's also possible for the root source file to import a different file which actually does the export of WinMain. The start code does not have access to find out what is or isn't exported, and it's using @hasDecl as a way for the root source file to communicate in a convenient way that it wants to be in control of this symbol.

So, for now, the thing to do is slap a pub on there while waiting for the language to stabilize. I'm confident that moving the logic out of the compiler and into the start code was a good move; let's let it guide us further along the path toward what the final language / standard library will look like.

@mogud
Copy link
Contributor

mogud commented Dec 8, 2019

@andrewrk Did you considered about adding builtin user defined properties support? Maybe calling convention is a relevant stuff. In addition, some useful properties like deprecated and future used can be introduced.

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 stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants