-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Zig doesn't detect wWinMain symbol in C files. #18621
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
Comments
@squeek502 related to #17763 ? |
Minimal test case: // wwinmain.c
#include <windows.h>
int APIENTRY wWinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PWSTR cmdline, int cmdshow) {
return 0;
} Fails:
Targeting the MSVC ABI does work, so it's very likely MinGW related:
So probably caused by #16109, but still need to confirm that. |
Hm, I can't actually get
Using #include <windows.h>
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PSTR cmdline, int cmdshow) {
return 0;
} |
You didn't |
Tried that, didn't seem to change anything and isn't done in the OP reproduction. EDIT: Also,
|
In usual C windows app, wWinMain would be a "wide", meaning Unicode entry. For Unicode app, one #defines UNICODE or _UNICODE before including windows.h. (and pass the linker flag to indicate that the app is for the windows subsystem). Not sure what magic zig does for Wndows targets, though. |
Unless I'm mistaken, I think any magic being done is performed by the linker. From the /ENTRY docs:
In this case, Here's the
And here's the
And here's the
|
Have you tried putting pub const wWinMain = void; in your root source file? |
Note that this is a problem with compiling C files, not Zig files. Minimal reproduction is #include <windows.h>
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PSTR cmdline, int cmdshow) {
return 0;
}
This worked in 0.11.0. |
cc @ypsvlq on the off-chance you have some insight on this. EDIT: This seems potentially relevant: https://sourceforge.net/p/mingw-w64/mailman/mingw-w64-public/thread/20221113114053.ze3h5pt4s7do53fi@pali/ |
In msvc, the linker detects wWinMain/WinMain/wmain/main and chooses the appropriate startup code. Currently Zig doesn't build crtexewin, but other changes might be needed, I'll look in more detail later. |
I'm encoutering this using zig 0.11.0, and tested back on 0.10.0 this also appears. I don't think this was supported in zig and it should not be marked as regression?
minimal repro int wmain(int argc, wchar_t* argv[]) {
return 0;
} |
@chawyehsu WinMain and wmain are two different things. |
@RossComputerGuy Did I misunderstand here? I'm talking about the issue of unicode entry against mingw here. I know the difference between WinMain and wmain. |
See #19399 (comment): the regression is with regards to |
I'm getting similar with error: lld-link: undefined symbol: WinMain I note that a search of the zig-cache\o doesn't find the tclsh.pdb or tclsh.lib shown in the lld-link error line above - but I have generated dlls for this project where the .pdb files are output both in the zig-cache and zig-out. |
@juliannoble What main function are you expecting the compiler to use? See #19399 (comment) for what you need to pass to |
Sorry, I don't know enough about entry points and specifically how tclsh works to answer. |
I think this is just a case of the error message being confusing. If I try to compile a completely empty C file (with no main function) I get the same error as you:
So what's likely happening is that you're trying to compile an executable but the linker is unable to find any suitable main symbol at all. If so, this is unrelated to this issue (this issue is about wanting to use WinMain/wWinMain as your main function) and I'd suggest asking for help with your problem in one of the community spaces. |
I ran into this error while using
The reason was that |
Zig Version
0.12.0-dev.2159+7916cf6f8
Steps to Reproduce and Observed Behavior
Compile some C code that has a wWinMain startup point. (my use case: C application built by build.zig)
Observe that compiler ignores wWinMain definition and instead complains about the absence of main.
Side notes:
This issue is not present on the 0.11.0 version.
Declaring main instead of wWinMain works. This is the current workaround that I am using.
This is observed on both x86-windows and x86_64-windows
Zig build log: https://paste.sr.ht/~electrosssnake/da3a6d579b24d868d2f32f75f3c7b95b43686142
Whole build.zig: https://paste.sr.ht/~electrosssnake/ce4e6a9b7f184d910e2b309381da62ccf871b922
C file(start.c) that contains windows startup symbol: https://paste.sr.ht/~electrosssnake/8ac72ced13aed44f53549fe354baa9adeb068b56
Expected Behavior
Zig correctly detects wWinMain and builds the application.
The text was updated successfully, but these errors were encountered: