-2

I always get this error 'Undefined reference to WinMain@16' after creating a class in Code::Blocks. I have to restart it to make the program works.

Why ?

Thank you!

tonystrawberry
  • 102
  • 1
  • 2
  • 12
  • Already was here: http://stackoverflow.com/questions/21500724/c-undefined-reference-to-winmain16-codeblocks And here: http://forums.codeblocks.org/index.php?topic=11608.0 – Arkady Jun 05 '14 at 14:08
  • @πάνταῥεῖ I don't think that is a good duplicate. The OP's error message is about `WinMain` and the reason is because on Windows the g++ error message for a program that has no `main()` function is to miss `WinMain`. Writing a standard `main()` function solves the problem. – Csq Jun 05 '14 at 14:20
  • @Csq It's mentioned there in an answer: http://stackoverflow.com/a/22160071/1413395 – πάντα ῥεῖ Jun 05 '14 at 14:22
  • @πάνταῥεῖ Yep, still [this](http://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16) is a better duplicate, especially with [this](http://stackoverflow.com/a/12378382/680982) answer (as it is also mentioned in the first comment linked by your answer). – Csq Jun 05 '14 at 14:23

1 Answers1

0

If you have only one file - your class - and you trying to compile it, you will get this error because file don't have int main() function. It's required by linker to create executable (start point of program).

If you have project with classes, you must have one main function, for example in main.cpp file :)

Also, check that you selected a Console application - GUI (Windows application) neeed WinMain function instead of classical main.

Of course, this is about normal program - library have other requirements.

aso
  • 1,331
  • 4
  • 14
  • 29