C++致命错误 LNK1120:1 个未解析的外部
是什么导致了这个错误?我用谷歌搜索了它,我发现的前几个解决方案是库和主函数出了问题,但在我的问题中似乎都很好,我什至重新输入了两者!可能是什么原因造成的?
这可能会有所帮助:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
来自 msdn
From msdn
我就犯过一次这个错误。
事实证明,我将程序命名为 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
我的问题是
int Main()
而不是
int main()
祝你好运
My problem was
int Main()
instead of
int main()
good luck
嗯,看来您缺少对某些库的引用。我有类似的错误通过添加对 #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")
我的情况:我定义了类解构函数的原型,但忘记定义主体。
My case: I defined a prototype of the class de-constructor, but forgot to define the body.
就我而言,头文件和 .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 wasLPCWSTR
.当我在
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 thebar.hpp
but forgot to define its body in the class namespace. I initially wrotefoo() const { /* body */ }
in thebar.cpp
file instead ofbar::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.
当我没有定义 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.
在我的特定情况下,发生此错误是因为
.vcproj
文件中未引用我添加的文件。In my particular case, this error error was happening because the file which I've added wasn't referenced at
.vcproj
file.就我而言,当我在“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.
我遇到了同样的错误。对我来说,这是因为我尝试在 .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.
就我而言,我完全忘记添加 main() 函数。
In my case I had forgotten to add the main() function altogether.