I just try build this example for GCC.
But I got several problems.
My system is:
c:\windows\servicing\LCU\Package_for_RollupFix~31bf3856ad364e35~amd64~~19041.2486.1.5\amd64_microsoft-windows-netapi32_31bf3856ad364e35_10.0.19041.2130_none_0202483cb6bb2fc6\f\netapi32.dll
cmd
as consoleI try: gcc main.c -o main.exe -lnetapi32
But gcc
returned:
undefined reference to `WinMain' collect2.exe: error: ld returned 1 exit status
OK - wrong entry point.
Changed wMain
in WinMain
.
Result:
main.c:11:5: error: conflicting types for 'WinMain'; have 'int(int, wchar_t **)' {aka 'int(int, short unsigned int **)'}
11 | int WinMain(int argc, wchar_t *argv[])
| ^~~~~~~
In file included from c:/msys64/ucrt64/include/windows.h:70,
from main.c:8:
c:/msys64/ucrt64/include/winbase.h:1128:14: note: previous declaration of 'WinMain' with type 'int(struct HINSTANCE__ *, struct HINSTANCE__ *, CHAR *, int)' {aka 'int(struct HINSTANCE__ *, struct HINSTANCE__ *, char *, int)'}
1128 | int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
What is wrong?
wmain
is an extension by Microsoft, and insofar I know not supported by gcc. You need to change the entry function to a standard int main(int argc, char **args)
. You can also use WinMain
but then you'll have to use int WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)