0

How do I resolve this error:

Error 1 error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup 

I also define all the functions inside cai.cpp. However I did not upload it due to too many lines of codes. I do include the .h file into cai.cpp. I am confused as to what this error is asking.

main.cpp file

#include "cai.h"

int main()
{
    CAI test;
    test.StartTest();

}

cai.h file

class CAI
{
public:

    void StartTest();
    bool AskRandomMultiplicationQuestion();
    bool AskRandomDivisioQuestion();


private:
    void PrintRandomGoodJob();
    void PrintRandomEncouragementMessage();
    int ChooseRandomNumber();
    void PrintTestSummary(int, int, int);

};
monkey doodle
  • 690
  • 5
  • 12
  • 22

2 Answers2

5

Set your sub system to console instead of windows, or add the winmain function as your entry point.

See: http://msdn.microsoft.com/en-us/library/fcc1zstk.aspx

And:

difference between Console (/SUBSYSTEM:CONSOLE) and Windows (/SUBSYSTEM:WINDOWS)

Community
  • 1
  • 1
paulm
  • 5,629
  • 7
  • 47
  • 70
  • yeah you are using main() and it requires winmain, try making new project, add code to it or supply it winmain entry point – Ali Kazmi Oct 02 '14 at 06:45
3

This error

Error 1 error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

means that you're compiling a Windows exe, not a console exe, and you're expected to provide a WinMain. The linker cannot find your implementation of it, so it screams out that error.

You choose the project type (Windows or console) when the project is added to the solution, or in the settings (Tools > Options > Linker > System > SubSystem) if you want to change it after creation.

Johann Gerell
  • 24,991
  • 10
  • 72
  • 122