0

I'm currently working on an entry level C++ project to code the game mastermind (a secret code is generated and the user tries to crack it). We are just learning the basics of C++ (OOP, arrays and vectors, etc.), so the code seems to work fine. However, everytime I attempt to compile my .cpp files for the 3 classes I have, each one has some error I have never seen referring to WinMain, right here

18 C:\crossdev\src\mingw-w64-v3-git\mingw-w64-crt\crt\crt0_c.c undefined reference to `WinMain' C:\Users\xxx\OneDrive\Desktop\xxx\collect2.exe [Error] ld returned 1 exit status

This is the universal error message across the 3 .cpp files, the header files and main file compile fine. Any ideas what went wrong? I've done a couple assignments similar to this no problem...

Heres the code to one of the classes for reference

#include "response.hpp"

using namespace std;

response::response()
{
    numCorrect = 0;
    numIncorrect = 0;
}


response::response(int correct, int incorrect)
{
    numCorrect = correct;
    numIncorrect = incorrect;
} 


int response::getNumCorrect()
{
    return numCorrect;
} 

int response::getNumIncorrect()
{
    return numIncorrect;
} 


void response::setCorrect(int correct)
{
    numCorrect = correct;
} 

void response::setIncorrect(int incorrect)
{
    numIncorrect = incorrect;
} 

bool operator == (const response& lhs, const response& rhs)
{
    return ((lhs.numCorrect == rhs.numCorrect) && (lhs.numIncorrect == rhs.numIncorrect));
} 

ostream& operator << (ostream& ostr, const response& out)
{
    ostr << "Correct: " << out.numCorrect << endl;
    ostr << "Incorrect: " << out.numIncorrect << endl;
    return ostr;
} 
parzival
  • 23
  • 4
  • 1
    I agree with the linker. I can't see a `main` function either. – user4581301 Feb 24 '21 at 19:39
  • It says it wants a `main` function, because it thinks each `.cpp` file you give it is a complete program. How exactly you fix it depends on the IDE and/or build system you use, but you didn't tell us what it is. Also header files don't need to be compiled. – HolyBlackCat Feb 24 '21 at 19:39
  • Duplicate of https://stackoverflow.com/questions/58324230/undefined-reference-to-winmain-c-mingw? – Thomas Feb 24 '21 at 19:41
  • @Thomas The linked thread is about `wWinMain` vs `main`/`winMain`, and doesn't seem to help much in this case. OP just needs to link their .cpp files together. – HolyBlackCat Feb 24 '21 at 19:43
  • 1
    You don't show what command you use for compiling/linking but If your code has `WinMain` instead of `main` then you need to pass `-mwindows` to MingW to tell it to think you are compiling a windows program instead of a console program. – Jerry Jeremiah Feb 24 '21 at 21:27
  • Related: https://stackoverflow.com/questions/45535838/in-the-mingw-compiler-what-is-the-mwindows-command-and-what-does-it-do https://gcc.gnu.org/onlinedocs/gcc/x86-Windows-Options.html Other things that might be related: https://stackoverflow.com/questions/4441551/how-to-stop-a-program-compiled-with-mingw-g-from-opening-a-console-window-in https://stackoverflow.com/questions/2752792/whats-the-equivalent-of-gccs-mwindows-option-in-cmake – Jerry Jeremiah Feb 24 '21 at 21:29

0 Answers0