LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

前端 未结 12 2011
广开言路
广开言路 2020-12-02 18:36

I have the following error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup,

There are a lot of threads relating to this error bu

相关标签:
12条回答
  • 2020-12-02 19:11

    I got this error while I was trying to turn off precompiled headers in a Console Application Project and removing the header file stdafx.h

    To fix this go to your project properties -> Linker -> SubSystem and change the value to Not Set

    In your main class, use the standard C++ main function protoype that others have already mentioned :

    int main(int argc, char** argv)
    
    0 讨论(0)
  • 2020-12-02 19:14

    Because it hasn't been mentioned yet, this was the solution for me:

    I had this error with a DLL after creating a new configuration for my project. I had to go to Project Properties -> Configuration Properties -> General and change the Configuration Type to Dynamic Library (.dll).

    So if you're still having trouble after trying everything else, it's worth checking to see if the configuration type is what you expect for your project. If it's not set correctly, the compiler will be looking for the wrong main symbol. In my case, it was looking for WinMain instead of DllMain.

    0 讨论(0)
  • 2020-12-02 19:16

    I had the problem before, but it was solved. The main problem was that I mistakenly spell the int main() function. Instead of writing int main() I wrote int mian()....Cheers !

    0 讨论(0)
  • 2020-12-02 19:17

    this main works in both linux and windows - found it through trial and error and help from others so can't explain why it works, it just does int main(int argc, char** argv)

    no tchar.h necessary

    and here is the same answer in Wikipedia Main function

    0 讨论(0)
  • 2020-12-02 19:20

    I find that when i choose option of Project->Properties->Linker->System->SubSystem->Console(/subsystem:console), and then make sure include the function : int _tmain(int argc,_TCHAR* argv[]){return 0} all of the compiling ,linking and running will be ok;

    0 讨论(0)
  • 2020-12-02 19:20

    I had this happen in Visual Studio 2015 too for an interesting reason. Just adding it here in case it happens to someone else.

    I already had number of files in project and I was adding another one that would have main function in it, however when I initially added the file I made a typo in the extension (.coo instead of .cpp). I corrected that but when I was done I got this error. It turned out that Visual Studio was being smart and when file was added it decided that it is not a source file due to the initial extension.

    Right-clicking on file in solution explorer and selecting Properties -> General -> ItemType and setting it to "C/C++ compiler" fixed the issue.

    0 讨论(0)
提交回复
热议问题