Reputation: 57
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
Upvotes: 1
Views: 4492
Reputation: 138
You didn't provide any of your code. And the problem I encountered is similar to this, so I'll describe the experience I had.
I was try out Dear ImGui library, and when I added the -municode option, the linker complained the same thing as yours. I did some searching, and found an answer to a similar question and another comment discussing a related problem, they both suggesting change "main" to "wmain". I did that, and the build was able to succeed. I'm not knowledgeable enough to provide any deeper information about the source of the problem though.
Upvotes: 0
Reputation: 2103
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
Upvotes: 0