5

I'm writing a C program and using Dev C++ to compile/run it.

However, it's coming up with the error:

undefined reference to 'WinMain'" and "[Error] Id returned 1 exit status"

What do these errors mean, and how do I solve them?

The WinMain error appears to be linked to line 18 of my code which is...

int read_char() { return getchar(); }

Any ideas? I'm a beginner with C, and I haven't found an answer to this question that I understand.

I presume it's because I'm using Windows. Would the code work on linux as it is perhaps?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Wolff
  • 1,051
  • 3
  • 18
  • 31

1 Answers1

7

This error means that the linker is looking for a function named WinMain to use as the entry point. It would be doing that because you configured the project to target the GUI subsystem, but did not provide a WinMain function.

My guess is that you want to produce a console application and have provided a main function. Target the console subsystem to resolve the problem.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I didn't configure the project at all really, I just copied and pasted the code from gedit. How do I produce a console appllication? I have provided a main function already. – Wolff Oct 20 '14 at 18:51
  • How did you create the dev c++ project? A gui or a console project. Did you try to change the dev c++ config from gui to console? – David Heffernan Oct 20 '14 at 19:31
  • I just did File -> New -> Source File I believe – Wolff Oct 20 '14 at 20:11
  • You must have done more than that surely. There must be a project workspace for this IDE. Did you look in the config for your project yet? Please tell me what you have tried? Do you know the difference between console and GUI app? – David Heffernan Oct 20 '14 at 20:13
  • Thanks. The problem for me was that I was m missing a main function. – Eyal Gerber Jul 20 '23 at 15:00