C++ 致命错误 LNK1120:1 个未解析的外部

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7410798/
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 16:53:39  来源:igfitidea点击:

C++ Fatal Error LNK1120: 1 unresolved externals

c++visual-studio-2010mainfatal-error

提问by Howdy_McGee

What is causing this error? I google'd it and first few solutions I found were that something was wrong with the library and the main function but both seem to be fine in my problem, I even retyped both! What could be causing this?

是什么导致了这个错误?我用谷歌搜索了它,我发现的前几个解决方案是库和主函数有问题,但我的问题似乎都很好,我什至重新输入了两个!什么可能导致这种情况?

This might be helpful:

这可能会有所帮助:

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

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

#include <iostream>
using namespace std;
int main()
{
    const double A = 15.0, 
                 B = 12.0, 
                 C = 9.0;
    double aTotal, bTotal, cTotal, total;
    int numSold;

    cout << "Enter The Number of Class A Tickets Sold: ";
    cin >> numSold;
    aTotal = numSold * A;

    cout << "Enter The Number of Class B Tickets Sold: ";
    cin >> numSold;
    bTotal = numSold * B;

    cout << "Enter The Number of Class C Tickets Sold: ";
    cin >> numSold;
    cTotal = numSold * C;

    total = aTotal + bTotal + cTotal;

    cout << "Income Generated" << endl;
    cout << "From Class A Seats $" << aTotal << endl;
    cout << "From Class B Seats $" << bTotal << endl;
    cout << "From Class C Seats $" << cTotal << endl;
    cout << "-----------------------" << endl;
    cout << "Total Income: " << total << endl;

    return 0;
}

回答by Drahakar

From msdn

来自 msdn

When you created the project, you made the wrong choice of application type. When asked whether your project was a console application or a windows application or a DLL or a static library, you made the wrong chose windows application (wrong choice).

Go back, start over again, go to File -> New -> Project -> Win32 Console Application -> name your app -> click next -> click application settings.

For the application type, make sure Console Application is selected (this step is the vital step).

The main for a windows application is called WinMain, for a DLL is called DllMain, for a .NET application is called Main(cli::array ^), and a static library doesn't have a main. Only in a console app is main called main

创建项目时,您选择了错误的应用程序类型。当被问及您的项目是控制台应用程序还是 Windows 应用程序或 DLL 或静态库时,您选择了错误的 Windows 应用程序(错误选择)。

返回,重新开始,转到文件-> 新建-> 项目-> Win32 控制台应用程序-> 命名您的应用程序-> 单击下一步-> 单击应用程序设置。

对于应用程序类型,确保选择了控制台应用程序(此步骤是至关重​​要的步骤)。

Windows 应用程序的 main 称为 WinMain,DLL 称为 DllMain,.NET 应用程序称为 Main(cli::array ^),静态库没有 main。仅在控制台应用程序中 main 称为 main

回答by Bob in SC

I incurred this error once.

我犯过一次这个错误。

It turns out I had named my program ProgramMame.ccpinstead of ProgramName.cpp

原来我已经将我的程序命名为 ProgramMame。ccp而不是 ProgramName。cp

easy to do ...

容易做...

Hope this may help

希望这可能会有所帮助

回答by Mahika

My problem was int Main()instead of int main()

我的问题是 int Main()而不是 int main()

good luck

祝你好运

回答by G droid

Well it seems that you are missing a reference to some library. I had the similar error solved it by adding a reference to the #pragma comment(lib, "windowscodecs.lib")

好吧,您似乎缺少对某个库的引用。我通过添加对#pragma comment(lib, "windowscodecs.lib")的引用解决了类似的错误

回答by Amir Twito

You must reference it. To do this, open the shortcut menu for the project in Solution Explorer, and then choose References. In the Property Pages dialog box, expand the Common Properties node, select Framework and References, and then choose the Add New Reference button.

你必须参考它。为此,请在解决方案资源管理器中打开项目的快捷菜单,然后选择引用。在“属性页”对话框中,展开“通用属性”节点,选择“框架和引用”,然后选择“添加新引用”按钮。

回答by funk

I have faced this particular error when I didn't defined the main() function. Check if the main() function exists or check the name of the function letter by letter as Timothy described above or check if the file where the main function is located is included to your project.

当我没有定义 main() 函数时,我遇到了这个特殊的错误。检查 main() 函数是否存在,或者像 Timothy 上面描述的那样逐个字母检查函数的名称,或者检查 main 函数所在的文件是否包含在您的项目中。

回答by dbz

In my particular case, this error error was happening because the file which I've added wasn't referenced at .vcprojfile.

在我的特定情况下,发生此错误错误是因为我添加的文件未在.vcprojfile.h 中引用。