Undefined reference to WinMain@16

I have seen posts about this problem before, and tried everything within them.

This code is for my Freshmen (9th grade) free class, and I am making a simple calculator with if/then statements. I have my first adding portion assembled, but when I try to compile/run it doesn't work.

Here's my code thus far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream.h>

using namespace std;

int add ( int x, int y )

{
{
  int typeofmath;


  cout<<"(1)Add/(2)Subtract/(3)Multiply/(4)Divide: ";
  cin>> typeofmath;
  cin.ignore();
  if ( typeofmath == 1 )
     { int x;
       int y;

  cout<<"Please enter the two numbers you want added: ";               //Goal: Figure out how the WinMain@16 error works/is/fix!!!
  cin>> x >> y;
  cin.ignore();
  cout<<"Your answer is "<< add ( x, y );
  cin.get();
}

int add ( int x, int y );

{
  return x + y;
}

}
}


Also, I have tried adding int main() and iostream.h

It doesnt work.
Last edited on
It looks like you accidentally made a windows application project, rather than a console project. This is why it is looking for the windows entry point 'WinMain', rather than the console entry point 'main'.

I suggest you create a new project, being careful to select "Console Application", and then copy the source code over from the old project to the new one.

PS: What is your IDE? You should really be #including "iostream" rather than "iostream.h" these days. ;)

PPS: If I were you I would check your code - there seem to be a few stray curly braces.
PPPS: Don't use "Console Application" if you use VC++, as that will be a huge hassle. Just make a new blank project instead.
Good point - the configuration wizard is annoying ;)
I don't think Visual Studio has an "iostream.h" header file though, so I guess the OP has a different IDE. But maybe I'm wrong...
I love the configuration wizard! hehe. I hated it when I didn't understand the precompiled header, though. :-S Not that I FULLY understand now. :-P

But true about the empty project. In Visual Studio, select Win32 Project, then in the Settings page select Empty Project. This way you'll be free of the precomppiled header.

And yes, it does have iostream, sstream, etc.
I assumed a precompiled header was just a header file that got compiled before being included to speed up compile times.

And yes, it does have iostream, sstream, etc.

Lol, I know it has the standard header files :P. What I was saying is that my version of MSVCE 2010 definitely doesn't have "iostream.h", i.e. the old style header file with the '.h' extension.
Last edited on
Doh! My bad. Did not catch that one.
Alright, I have re-done the code, and Ill include a bit more information this time.

I removed the .h, as it was useless. I tried using a different compiler (From the Code :: Blocks to DevC++) and both got similar errors. I have a feeling that it has to do with the int add (int x, int y) line of code, and the missing int main().

I am using the Code :: Blocks Compiler currently.

Also, creating a blank project did not fix the error, just caused confusion, as I could not create anything within the project.

Also, what is an IDE?

Included is the code, with a few of the stray curly braces removed :P
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>

using namespace std;

int add ( int x, int y);


{
{
  int typeofmath;


  cout<<"(1)Add/(2)Subtract/(3)Multiply/(4)Divide: ";
  cin>> typeofmath;
  cin.ignore();
  if ( typeofmath == 1 )

     { int x;
       int y;

  cout<<"Please enter the two numbers you want added: ";
  cin>> x >> y;
  cin.ignore();
  cout<<"Your answer is "<< add ( x, y );
  cin.get();
}

int add ( int x, int y );

{
  return x + y;
}

}
}

Also, what is an IDE?

It stands for Integrated Development Environment. It is a piece of software which combines an editor (usually with syntax highlighting and code completion) with a compiler and linker, and often many other plugins for various purposes.

I am using the Code :: Blocks Compiler currently.

In fact, Code::Blocks is an IDE. The compiler it uses by default is called MinGW. The same is true for Dev C++, which, I stress, you should no longer be using as it is abandonware (unless you mean wxDev C++).

missing int main().

Without an entry point of some kind (int main for console applications, INT WinMain for windows applications etc.), you cannot create an executable application. What exactly are you trying to do?
Sorry for the long reply time, the schools network has been down and I could not get home access.


I am trying to build a calculator with if/then statements. There are easier ways to do it, but with the little amount I have been taught, I figured this would be a challenging process :P

This is the first chunk, the adding portion. When I tried to compile it, I got the error.

So what can I do to fix the error? I need to declare a variable, such as int main or winmain, but I also need to include the x and y integers.

I stress, you should no longer be using as it is abandonware

I have uninstalled it and am back to Code::Blocks. I like the interface more too.

Also, I am on an age-old XP, not sure if that affects anything much.

Last edited on
on an age-old XP

XP is fine; it certainly won't be causing these problems.

back to Code::Blocks

Good decision!

So as for your error, does your program have either a int main() function or a INT WINAPI WinMain(...) function?
So as for your error, does your program have either a int main() function or a INT WINAPI WinMain(...) function?



No it does not. The code is seen above ^ and that's the complete first quarter. The only problem is that.

Also, again, sorry for the late response. With finals, this isn't a HIGH priority, but still up there.

Thanks for all help given so far :D
Also, again, sorry for the late response

No problem.

So you have no main function, or other entry point. You can't compile an executable therefore. Are you trying to make a library or something?
I am trying to make a calculator using only if-then statements, with a few other bits thrown in.

This is the first 1/4th, and I already have the other 3 parts ready to add to the code, except I can't get past this first error.
If you want to compile your code to a console program which runs, i.e. a .exe file, then you must have a main function. There is no other option. This is the console entry point. Without it you cannot define with which code your (console) program starts.

If all your code is in other functions, then just call them from main.

If you want these functions to be available to you when you write future programs, then you will need to compile your code into a static or dynamic library. These do not need an entry point.

Regards
-Xander314
Last edited on
Topic archived. No new replies allowed.