[c++] error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

While I am running the simple code as below I have two errors as following:

#include <iostream>
#include <string>
using namespace::std;

template <class Type>
class Stack
{
public:
    Stack (int max):stack(new Type[max]), top(-1), maxsize(max){}
    ~Stack (void) {delete []stack;}
    void Push (Type &val);
    void Pop (void) {if (top>=0) --top;}
    Type& Top (void) {return stack[top];}
    //friend ostream& operator<< (ostream&, Stack&);
private:
    Type *stack;
    int top;
    const int maxSize;
};

template <class Type>
void Stack <Type>:: Push (Type &val)
{
    if (top+1<maxsize)
        stack [++top]=val;
}

Errors:

MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

What Should I do?

This question is related to c++ visual-studio visual-c++

The answer is


The erudite suggestions mentioned above will solve the problem in 99.99% of the cases. It was my luck that they did not. In my case it turned out I was including a header file from a different Windows project. Sure enough, at the very bottom of that file I found the directive:

#pragma comment(linker, "/subsystem:Windows")

Needless to say, removing this line solved my problem.


Besides changing it to Console (/SUBSYSTEM:CONSOLE) as others have said, you may need to change the entry point in Properties -> Linker -> Advanced -> Entry Point. Set it to mainCRTStartup.

It seems that Visual Studio might be searching for the WinMain function instead of main, if you don't specify otherwise.


I'm not sure where to post this answer of mine but I think it's the right place. I came across this very error today and switching the subsystems didn't change a thing.

Changing the 64bit lib files to 32bit (x86) did the trick for me, I hope it will help someone out there !


If you use Unicode Character Set, but the entry wasn't set, you can specify /ENTRY:"wWinMainCRTStartup"


If you are using CMake, you can also get this error when you set SET(GUI_TYPE WIN32) on a console application.


If you are having this problem and are using Qt - you need to link qtmain.lib or qtmaind.lib


Include <tchar.h> which has the line:

#define _tWinMain wWinMain

If you actually want to use _tWinMain() instead of main() make sure your project relevant configuration have

  1. Linker-> System -> SubSystem => Windows(/SUBSYSTEM:WINDOWS)
  2. C/C++ -> Preprocessor -> Preprocessor Definitions => Replace _CONSOLE with _WINDOWS
  3. In the c/cpp file where _tWinMain() is defined, add:

    #include <Windows.h> #include <tchar.h>


Thats a linker problem.

Try to change Properties -> Linker -> System -> SubSystem (in Visual Studio).

from Windows (/SUBSYSTEM:WINDOWS) to Console (/SUBSYSTEM:CONSOLE)

This one helped me


If your project is Dll, then the case might be that linker wants to build a console program. Open the project properties. Select the General settings. Select configuration type Dynamic Library there(.dll).


i don't see the main function.

please make sure that it has main function.

example :

int main(int argc, TCHAR *argv[]){

}

hope that it works well. :)


As the others mentioned you can change the SubSystem to Console and the error will go away.

Or if you want to keep the Windows subsystem you can just hint at what your entry point is, because you haven't defined ___tmainCRTStartup. You can do this by adding the following to Properties -> Linker -> Command line:

/ENTRY:"mainCRTStartup"

This way you get rid of the console window.


Your tried to turn that source file into an executable, which obviously isn't possible, because the mandatory entry point, the main function, isn't defined. Add a file main.cpp and define a main function. If you're working on the commandline (which I doubt), you can add /c to only compile and not link. This will produce an object file only, which needs to be linked into either a static or shared lib or an application (in which case you'll need an oject file with main defined).

_WinMain is Microsoft's name for main when linking.

Also: you're not running the code yet, you are compiling (and linking) it. C++ is not an interpreted language.


Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to visual-studio

VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio? How to download Visual Studio Community Edition 2015 (not 2017) Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio Code pylint: Unable to import 'protorpc' Open the terminal in visual studio? Is Visual Studio Community a 30 day trial? How can I run NUnit tests in Visual Studio 2017? Visual Studio 2017: Display method references

Examples related to visual-c++

How to install Visual C++ Build tools? Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat) How to install numpy on windows using pip install? How to use _CRT_SECURE_NO_WARNINGS How to play or open *.mp3 or *.wav sound file in c++ program? What is C# equivalent of <map> in C++? The program can't start because MSVCR110.dll is missing from your computer error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj Identifier is undefined error LNK2001: unresolved external symbol (C++)