C++ 错误 LNK2019:未解析的外部符号 _WinMain@16 在函数 ___tmainCRTStartup 中引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6626397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 20:26:53  来源:igfitidea点击:

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

c++visual-studiovisual-c++

提问by NAIEM

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@16referenced in function ___tmainCRTStartup

MSVCRTD.lib(crtexew.obj):错误 LNK2019:_WinMain@16函数中引用的未解析的外部符号___tmainCRTStartup

What Should I do?

我该怎么办?

回答by Bohdan

Thats a linker problem.

那是链接器问题。

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

尝试更改属性 -> 链接器 -> 系统 -> 子系统(在 Visual Studio 中)。

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

Windows (/SUBSYSTEM:WINDOWS)控制台 (/SUBSYSTEM:CONSOLE)

This one helped me

这个帮了我

回答by Morten Kristensen

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:

或者,如果您想保留 Windows 子系统,您可以暗示您的入口点是什么,因为您还没有定义___tmainCRTStartup. 您可以通过将以下内容添加到Properties -> Linker -> Command line来做到这一点:

/ENTRY:"mainCRTStartup"

/ENTRY:"mainCRTStartup"

This way you get rid of the console window.

这样您就可以摆脱控制台窗口。

回答by David Casper

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

如果您遇到此问题并且正在使用 Qt - 您需要链接 qtmain.lib 或 qtmaind.lib

回答by mathiasfk

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

除了将其更改为Console (/SUBSYSTEM:CONSOLE)如其他人所说的,你可能需要更改入口点的属性- >链接器- >高级- >入口点。将其设置为mainCRTStartup

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

如果您没有另外指定,Visual Studio 似乎正在搜索 WinMain 函数而不是 main 函数。

回答by zaki

Include <tchar.h>which has the line:

包括<tchar.h>具有以下内容的行:

#define _tWinMain wWinMain

回答by Petronius

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

如果您使用 Unicode 字符集,但未设置条目,则可以指定 /ENTRY:"wWinMainCRTStartup"

回答by jefry da gucci

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

希望它运作良好。:)

回答by dream_world

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

如果您的项目是 Dll,则可能是链接器想要构建控制台程序。打开项目属性。选择常规设置。在那里选择配置类型动态库(.dll)。

回答by Another Joe

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 !

将 64 位 lib 文件更改为 32 位(x86)对我有用,我希望它会帮助那里的人!

回答by Alex

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

如果你真的想使用_tWinMain()而不是main()确保你的项目相关配置有

  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>

  1. 链接器-> 系统 -> 子系统 => Windows(/SUBSYSTEM:WINDOWS)
  2. C/C++ -> 预处理器 -> 预处理器定义 => 用 _WINDOWS 替换 _CONSOLE
  3. 在定义_tWinMain()的 c/cpp 文件中,添加:

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