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

发布于 2024-12-04 08:31:15 字数 1225 浏览 2 评论 0原文

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

这可能会有所帮助:

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;
}

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

#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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

如果没有 2024-12-11 08:31:15

来自 msdn

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

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

对于应用程序类型,请确保选择控制台应用程序
(这一步是至关重要的一步)。

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

From 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

不打扰别人 2024-12-11 08:31:15

我就犯过一次这个错误。

事实证明,我将程序命名为 ProgramMame.ccp 而不是 ProgramName.cpp

很容易做到...

希望这可能有所帮助

I incurred this error once.

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

easy to do ...

Hope this may help

涫野音 2024-12-11 08:31:15

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

祝你好运

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

good luck

倾城泪 2024-12-11 08:31:15

嗯,看来您缺少对某些库的引用。我有类似的错误通过添加对 #pragma comment(lib, "windowcodecs.lib") 的引用解决了它

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

用心笑 2024-12-11 08:31:15

我的情况:我定义了类解构函数的原型,但忘记定义主体。

class SomeClass {
    ~SomeClass(); //error
};

class SomeClass {
    ~SomeClass(){}; //no error
}

My case: I defined a prototype of the class de-constructor, but forgot to define the body.

class SomeClass {
    ~SomeClass(); //error
};

class SomeClass {
    ~SomeClass(){}; //no error
}
旧竹 2024-12-11 08:31:15

就我而言,头文件和 .cpp 文件中的参数类型不同。在头文件中,类型为 std::wstring,在 .cpp 文件中,类型为 LPCWSTR

In my case, the argument type was different in the header file and .cpp file. In the header file the type was std::wstring and in the .cpp file it was LPCWSTR.

青瓷清茶倾城歌 2024-12-11 08:31:15

当我在 bar.hpp 中编写原型成员函数 void foo() const; 但忘记在类命名空间中定义其主体时,出现了此错误。我最初在 bar.cpp 文件中编写 foo() const { /* body */ } 而不是 bar::foo() const { /* body */ }

I had this error when I wrote a prototype member function void foo() const; in the bar.hpp but forgot to define its body in the class namespace. I initially wrote foo() const { /* body */ } in the bar.cpp file instead of bar::foo() const { /* body */ }

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

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.

俯瞰星空 2024-12-11 08:31:15

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

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.

耳钉梦 2024-12-11 08:31:15

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

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

伤感在游骋 2024-12-11 08:31:15

就我而言,当我在“public”访问说明符下声明一个函数时,我收到了此错误。当我将该函数声明为私有时,问题得到解决。

In my case I got this error when I had declared a function under 'public' access specifier. Issue got resolved when I declared that function as private.

一张白纸 2024-12-11 08:31:15

我遇到了同样的错误。对我来说,这是因为我尝试在 .cpp 文件中实现内联函数,而不是将其放在定义所在的头文件中。因此,当我尝试包含头文件并使用该函数时,出现此错误。

I have encountered the same error. For me it turned out to be because I tried to implement an inline function in the .cpp file, instead of putting it in the header file, where the definition is. Therefore when I tried to include the header file and use the function, I got this error.

草莓味的萝莉 2024-12-11 08:31:15

就我而言,我完全忘记添加 main() 函数。

In my case I had forgotten to add the main() function altogether.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文