cgccwinmain

GCC - Compiling C undefined reference to `wWinMain'


I'm trying to compile C with gcc in command prompt but I'm getting this undefined reference to `wWinMain' error.

I was getting undefined reference to `WinMain' first but I fixed that by adding the argument:

-municode

Now `wWinMain' is undefined. How to fix this?

C:\Development\WA\Library\Backend\C\CB\CB>gcc CB.c -lssl -lcrypto -municode
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: 
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_w.o):crt0_w.c:(.text+0x21): undefined reference to `wWinMain'
collect2.exe: error: ld returned 1 exit status

Solution

  • gcc CB.c -lssl -lcrypto will compile and link an application, which on Windows defaults to a windowed application for which the entry point is WinMain (which your library obviously does not have nor need).

    Adding the -municode just instructs the system to use the windows unicode API and then the entry point becomes wWinMain, and you still have the same problem.

    To build a DLL, add -shared: gcc CB.c -shared -lssl -lcrypto