Undefined Reference To Winmain 16 Dev C%2b%2b

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

Undefined Reference To Winmain 16 Dev C++ Test

Once added, it found main. Also, the nature of how this works means that mingw is trying to help by providing its own main which in turn calls WinMain. GUI programs would only have WinMain and the main stub in mingw is used to get there. /download-game-crash-of-cars-mod-apk-offline.html. Best minecraft animation software for mac. If you have a main, then it uses that instead. – Jeff Muir Mar 23 '16 at 0:53.

  • Undefined reference Put simply, the “undefined reference” error means you have a reference (nothing to do with the C reference type) to a name (function, variable, constant etc.) in your program that the linker cannot find a definition for when it looks through all the object files and libraries that make up your project.
  • Linker error undefined reference to `. Is the mangled name for the WinMain entry point. ↳ C Development.
  • WinMain replaces main as the entry point for Windows Applications so either you were trying to right a Windows application and left out WinMain or you wern't trying to write a Windows application and (hopefully) have a main but have compile/link with flags that tell the compiler/linker that this is a Windows application and probably linked with.
  • Once added, it found main. Also, the nature of how this works means that mingw is trying to help by providing its own main which in turn calls WinMain. GUI programs would only have WinMain and the main stub in mingw is used to get there. If you have a main, then it uses that instead. – Jeff Muir Mar 23 '16 at 0:53.
  • Re: Resolved but why? - undefined reference to ' email protected ' « Reply #1 on: December 02, 2009, 10:23:47 am » If you compile a single file to an executable with CB, that file must contain a main function.

Undefined Reference To Winmain@16' C++

P: 1
Hey! When trying to compile the code for a ordered vector class I get the following error:
[Linker error] undefined reference to `WinMain@16'
Anyone have any idea what I might be doing wrong? I've been through this code multiple times and have no idea what would cause an error like this, I've never seen one like it before. Any help would be greatly appreciated.
The class is supposed to be able to create a sorted list of vectors of type Object. If an object is added to the list it places it in the proper order (ie you want to put in a 5 in the list 2 3 4 6, the 5 would be inserted between the 4 and 6)
Code is as follows:
  1. #include <stdlib.h>
  2. #include <iostream>
  3. #ifndef _ORDEREDVECTOR_H
  4. #define _ORDEREDVECTOR_H
  5. template <class Object>
  6. class orderedVector
  7. {
  8. public:
  9. orderedVector(int n);
  10. orderedVector( );
  11. orderedVector(const orderedVector & v);
  12. virtual ~orderedVector( );
  13. void dissolve ( );
  14. void add (const Object x);
  15. void remove (const Object x);
  16. void removeAt (int i);
  17. Object & operator [](int i);
  18. int length( ) const;
  19. bool isEmpty( ) const;
  20. bool contains(const Object x);
  21. private:
  22. Object * buffer;
  23. int size, capacity;
  24. void reserve(int newCapacity);
  25. void resize(int newCap) {reserve(newCap);}
  26. };
  27. template <class Object>
  28. orderedVector<Object>::orderedVector( ) :size(0),capacity(0),buffer(0){}
  29. template <class Object>
  30. orderedVector<Object>::orderedVector(int n): size(0), capacity(n), buffer(0)
  31. {
  32. if (n < 0)
  33. {
  34. cerr << 'Error: You can't create a vector with a negative capacity!n';
  35. exit(1);
  36. }
  37. }
  38. template <class Object>
  39. orderedVector<Object>::orderedVector(const orderedVector & v)
  40. {
  41. if (this &v)
  42. {
  43. cerr << 'Error: You can't copy a vector onto itself!n';
  44. exit(1);
  45. }
  46. buffer = 0;
  47. buffer = new Object[v.capacity];
  48. size = v.length( );
  49. capacity = v.capacity;
  50. for (int i = 0; i < v.length( ); i++)
  51. {
  52. buffer[i] = v.buffer[i];
  53. }
  54. }
  55. template <class Object>
  56. orderedVector<Object>::~orderedVector( )
  57. {
  58. delete [ ] buffer;
  59. }
  60. template <class Object>
  61. void orderedVector<Object>::add(const Object x)
  62. {
  63. if (size capacity)
  64. resize(capacity + 5);
  65. if (size 0)
  66. buffer[0] = x;
  67. else
  68. {
  69. for (int i = 0; i < size; i++)
  70. {
  71. if (x <= buffer[i])
  72. {
  73. int j = size;
  74. while (j > i)
  75. {
  76. buffer[j] = buffer[j-1];
  77. j--;
  78. }
  79. buffer[i] = x;
  80. }
  81. }
  82. }
  83. size++;
  84. }
  85. template <class Object>
  86. void orderedVector<Object>::remove(const Object x)
  87. {
  88. bool temp;
  89. for (i = 0; i < size; i++)
  90. {
  91. if (buffer[i] x)
  92. temp = true;
  93. else
  94. temp = false;
  95. }
  96. if (temp false)
  97. {
  98. cerr << 'Error: Object doesn't exist!n';
  99. exit(1);
  100. }
  101. else
  102. {
  103. for (int i = 0; i < size; i++)
  104. {
  105. int j = i;
  106. while (j < size - 1)
  107. {
  108. buffer[j] = buffer[j+1];
  109. j++;
  110. }
  111. }
  112. size--;
  113. }
  114. }
  115. template <class Object>
  116. void orderedVector<Object>::removeAt(const int i)
  117. {
  118. if (i < 0 i >= size)
  119. {
  120. cerr << 'Error: Index out of range!n';
  121. exit(1);
  122. }
  123. int j = i;
  124. while (j < size - 1)
  125. {
  126. buffer[j] = buffer[j+1];
  127. j++;
  128. }
  129. size--;
  130. }
  131. template <class Object>
  132. Object & orderedVector<Object>::operator [] (int i)
  133. {
  134. if (i < 0 i >= size)
  135. {
  136. cerr << 'Error: Index out of range!n';
  137. exit(1);
  138. }
  139. return buffer[i];
  140. }
  141. template <class Object>
  142. int orderedVector<Object>::length( ) const
  143. {
  144. return size;
  145. }
  146. template <class Object>
  147. bool orderedVector<Object>::isEmpty( ) const
  148. {
  149. return size 0;
  150. }
  151. template <class Object>
  152. bool orderedVector<Object>::contains(const Object x)
  153. {
  154. bool temp;
  155. for (i = 0; i < size; i++)
  156. {
  157. if (buffer[i] x)
  158. temp = true;
  159. else
  160. temp = false;
  161. }
  162. return temp;
  163. }
  164. template <class Object>
  165. void orderedVector<Object>::reserve(int newCap)
  166. {
  167. if (buffer 0)
  168. {
  169. size = 0;
  170. capacity = 0;
  171. }
  172. if (newCap <= capacity)
  173. return;
  174. Object * newBuffer = new Object[newCap];
  175. for (int i = 0; i < size; i++)
  176. newBuffer[i]=buffer[i];
  177. capacity = newCap;
  178. delete [ ] buffer;
  179. buffer = newBuffer;
  180. }
  181. #endif