0

How to fix the following error message when trying to compile C++ console application project on Code::Blocks?

undefined reference to `WinMain'

All other questions on Stack Overflow are about "WinMain@16", which is not the case here.

1 Answers1

1

WinMain is linked to in windows when you want to create a windows application.

https://learn.microsoft.com/en-us/windows/win32/learnwin32/winmain--the-application-entry-point

For the complier to look for the main function you will have to change at the linker stage that it is a console application and not a windowed one.

Or you might just need to restart CodeBlocks: C++ undefined reference to WinMain@16 (Code::Blocks)

Or you might have just have deleted main() ;)

Lasersköld
  • 2,028
  • 14
  • 20
  • In fact, I found out that I deleted the `main()` function by mistake. If you add this thesis to your answer I'll mark it as the correct answer to my question. – BsAxUbx5KoQDEpCAqSffwGy554PSah Nov 11 '22 at 14:25
  • 1
    Nice that you found a solution :P – Lasersköld Nov 11 '22 at 14:27
  • It's funny how people (me) can entangle on increasingly complex solutions for really simple problems. I had already tried to change the linker setting before asking here. Shame on me. – BsAxUbx5KoQDEpCAqSffwGy554PSah Nov 11 '22 at 14:32
  • 1
    Yes that pattern is interesting. I have the same. Getting stuck on a problem in four hours. Testing "everything", then take an hour formulating a question that is possible to post on stack overflow, and then five minutes later realize the solution, before anyone answers. Solving problems is not a simple process. – Lasersköld Nov 12 '22 at 09:16