LNK2019: unresolved external symbol _main referenc

2019-01-13 15:46发布

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

There are a lot of threads relating to this error but none of those solutions worked for me. And, none explained why this error is here.

I tried:

have not tried and suspect that these also will not work:

why am I getting this error and what is the solution?

12条回答
The star\"
2楼-- · 2019-01-13 16:22

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

查看更多
一夜七次
3楼-- · 2019-01-13 16:24

In my case, it's because I accidentally removed (not deleted) the stdafx.h and targetver.h files in the Header Files section.

Add these files back to Header Files and the problem is solved.

I had these:

#pragma comment( linker, "/entry:\"mainCRTStartup\"" ) // set the entry point to be main()

I just need to comment that (by prepending //) and it's good.

查看更多
Summer. ? 凉城
4楼-- · 2019-01-13 16:27

I had this error when accidentally putting the wmain inside a namespace. wmain should not be in any namespace. Moreover, I had a main function in one of the libs I was using, and VS took the main from there, what made it even stranger.

查看更多
你好瞎i
5楼-- · 2019-01-13 16:29

I had this problem minutes ago. It went away when I added 'extern "C"' to the main() definition.

Oddly, another simple program I wrote yesterday is almost identical, does not have the extern "C", yet compiled without this linker error.

This makes me think the problem is some subtle setting to be found deep in some configuration dialog, and that 'extern "C"' doesn't really solve the underlying problem, but superficially makes things work.

查看更多
霸刀☆藐视天下
6楼-- · 2019-01-13 16:29

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 !

查看更多
来,给爷笑一个
7楼-- · 2019-01-13 16:31

Screen snapshot Visual Studio 2015

Set the system to console, following the previous suggestions. Only, also had to change the character set to Unicode, see the snapshot of Visual Studio 2015 above.

查看更多
登录 后发表回答