error LNK2019: unresolved external symbol _WinMain

2019-01-01 10:21发布

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?

11条回答
后来的你喜欢了谁
2楼-- · 2019-01-01 10:45

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

查看更多
墨雨无痕
3楼-- · 2019-01-01 10:47

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

查看更多
几人难应
4楼-- · 2019-01-01 10:47

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.

查看更多
公子世无双
5楼-- · 2019-01-01 10:49

Include <tchar.h> which has the line:

#define _tWinMain wWinMain
查看更多
倾城一夜雪
6楼-- · 2019-01-01 10:52

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. :)

查看更多
大哥的爱人
7楼-- · 2019-01-01 10:53

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).

查看更多
登录 后发表回答