C++ Fatal Error LNK1120: 1 unresolved externals

蓝咒 提交于 2019-11-26 11:26:00

问题


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

回答1:


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




回答2:


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




回答3:


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

good luck




回答4:


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




回答5:


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.




回答6:


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.




回答7:


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



来源:https://stackoverflow.com/questions/7410798/c-fatal-error-lnk1120-1-unresolved-externals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!