473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

What do I do when I get the error, "undefined reference to WinMain@16"

Hi everyone,

I'm new to programming with C++ and I'm using Code::Blocks as my compiler. I keep getting the error "undefined reference to WinMain@16" and I have no idea how to fix it. My code is supposed to do different things with fractions, but anyway here is my code:(all code is in a project)

myFracDr.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "frac.h"
  2. #include "gcd.h"
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int x,y;
  10.     cout << "Enter positive integer x: ";
  11.     cin >> x;
  12.     cout << "Enter positive integer y: ";
  13.     cin >> y;
  14.     cout << FractionType::Initialize(x,y) << endl;
  15.  
  16.     system("pause"); //keeps window open
  17.     return 0;
  18. }
  19.  
myFrac.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "frac.h"
  2. #include "gcd.h"
  3.  
  4. void FractionType::Initialize(int numerator, int denominator)
  5. // Function: Initialize the fraction
  6. // Pre:  None
  7. // Post: numerator is stored in num; denominator is stored in
  8. //       denom
  9. {
  10.     num = numerator;
  11.     denom = denominator;
  12.     int cfactor = gcd(num, denom); // finds commom factor
  13.     num = num/cfactor; //reduces numerator
  14.     denom = denom/cfactor; //reduces denominator
  15. }
  16. int FractionType::NumeratorIs()
  17. // Function: Returns the value of the numerator
  18. // Pre:  Fraction has been initialized
  19. // Post: numerator is returned
  20. {
  21.     return num;
  22. }
  23. int FractionType::DenominatorIs()
  24. // Function: Returns the value of the denominator
  25. // Pre:  Reaction has been initialized
  26. // Post: denominator is returned
  27. {
  28.     return denom;
  29. }
  30.  
  31. bool FractionType::IsZero()
  32. // Function: Determines if fraction is zero
  33. // Pre:  Fraction has been initialized
  34. // Post: Returns true if numerator is zero
  35. {
  36.     return (num == 0);
  37. }
  38.  
  39. bool FractionType::IsNotProper()
  40. // Function: Determines if fraction is a proper fraction
  41. // Pre:  Fraction has been initialized
  42. // Post: Returns true if num is greater than or equal to denom
  43. {
  44.     return (num >= denom);
  45. }
  46.  
  47. int FractionType::ConvertToProper()
  48. // Function: Converts the fraction to a whole number and a
  49. //       fractional part
  50. // Pre:  Fraction has been initialized, is in reduced form, and
  51. //       is not a proper fraction
  52. // Post: Returns num divided by denom
  53. //       num is original num % denom; denom is not changed
  54. {
  55.     int result;
  56.     result = num / denom;
  57.     num = num % denom;
  58.     return result;
  59. }
  60.  
gcd.cpp (finds greatest common divisor)
Expand|Select|Wrap|Line Numbers
  1. int gcd(int x, int y)
  2. {
  3.     if (y==0)
  4.     {
  5.         return x;
  6.     }
  7.     else
  8.     {
  9.         while (y>0)
  10.         {
  11.             int step1 = x%y;
  12.             x = y;
  13.             y = step1;
  14.             if (x%y==0)
  15.             {
  16.                 return y;
  17.             }
  18.         }
  19.     }
  20.     return 0;
  21. }
  22.  
then I just have to two header files (frac.h and gcd.h)that I know are correct

Thank you for looking!
Feb 6 '12 #1
9 10309
weaknessforcats
9,208 Expert Mod 8TB
You have created a project for a Windows program rather than a console application. A Windows program has a WinMain() rather than a main().
Feb 7 '12 #2
I thought so too, but when I go into "Project/Target Options" and under "Type" is says "Console". I changed it to WinMain() just to try but I got the same error.
Feb 7 '12 #3
weaknessforcats
9,208 Expert Mod 8TB
This is the same error Visual C++ puts out when yu have a Windows project instead of a console application project.

I don't use your compiler so I can't provide exact corrective steps.
Feb 7 '12 #4
Ok so I remade the project with the same code just to see if anything got messed while I was making it and now I'm getting a different error message: "In function 'int main()': (line 17) error: cannot call member function 'void FractionType::Initialize(int, int)' without object"

Any idea what to do about that?

Thank you for trying to help me.
Feb 7 '12 #5
weaknessforcats
9,208 Expert Mod 8TB
You need an object to call a member function:

Expand|Select|Wrap|Line Numbers
  1. FractionType obj;
  2.              obj.Initialize();
otherwise the compiler has no idea what object you want initialized.

BTW: These kinds of initializing functions in C++ are called constructors. So if FractionType::Initialize(int,int) becomes FractionType::FractionType(int,int) then the compiler will call it withour you needing to remember to code the call:

Expand|Select|Wrap|Line Numbers
  1. FractionType obj(3,4);   
  2. //
  3. //when you get here FractionType::FractionType(3,4) has already been called
  4. //
BTW2: If you do this remember that constructors have no return types so remove the void.
Feb 7 '12 #6
I don't completely understand what you are telling me to do. I'm sorry, I'm really new to programming
Feb 7 '12 #7
Never mind. I got what you were saying. Thank you so much for your time!
Feb 7 '12 #8
I have the same problem did u fixed it??
Sep 21 '13 #9
weaknessforcats
9,208 Expert Mod 8TB
@lerions
Please start a new thread. I don't know what problem you are talking about since several were talked about here.
Sep 21 '13 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Steven T. Hatton | last post by:
Scroll to the bottom and read the last part first. I've been trying very diligently to 'modularize' the code from TC++PL3E found here: http://www.research.att.com/~bs/matrix.c I keep getting...
0
by: howie | last post by:
I've upgraded a vb6 application to vb .net and am having an issue. whenever I try to set the recordset property of the VB6.adodc object in .net and run the application I get the error “object...
6
by: mihailsmilev | last post by:
Hello, let me first describe the situation: I am developing an application using Qt Designer 3.3.5 on OpenSuSE Linux for my mp3 player. So I need to get the id3 tags from the mp3 files, and I've...
1
by: Shuaib | last post by:
Hey! I am trying to embedd python into a C programe of mine. But when I try to compile the C code, gcc gives errors like "undefined reference to `Py_Finalize'" and the same kind for all the...
3
by: s.z.s | last post by:
Hi! I hope the solution to that is not too stupid... I've got three files: <snip test_main.cc> #include"test.hh" int main(void) { A<inta1; a1.saywhat();
8
by: Soneji | last post by:
Hello all! ( again ) Once more, I have a problem that seems unsolvable by me. I'm getting the, seemingly common, "undefined reference" linking error. I've tried quite a few things, but...
16
by: Micko1 | last post by:
Hello there :) I have been using Visual Studio on a program which I have just completed, however I need to have it compiling using a unix based compiler, when I try in cygwin, I get the following...
4
by: steve | last post by:
Hi, I am trying to compile a sample program using gcc. The program requires headers so I put the header files and corresponding source files into one folder. Then I ran the command 'gcc prog.c -o...
1
by: ashjas | last post by:
Hello, i am trying to compile a code(main.cpp) which uses a function that is declared in a header file that is within the directory where the main.cpp file resides so the header is included as ...
8
Motoma
by: Motoma | last post by:
Good evening everyone. I am starting to re-explore C++, and I wanted to build a singleton class. Unfortunately, when I set things up as I do in PHP, it doesn't work out for me. I hope that the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.