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:
- wWinMainCRTStartup as entry point in the linker properties http://social.msdn.microsoft.com/Forums/en/vclanguage/thread/14e85604-6929-4707-a22e-8cdf596926a6
- set the linker to "Windows" (same thread as above)
- Right click on solution name->Add->Existing Item->file with main (same thread as above)
include error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
- try Project + properties, C/C++, Code generation, Buffer security check = No http://social.msdn.microsoft.com/Forums/hi-IN/vclanguage/thread/e2ea62c3-beb3-47a4-8963-60b799e3375a
- Options: C/C++, Code generation, Runtime library=/MTd; C/C++, Code generation, Basic Runtime Checks=default; C/C++, Code generation, Buffer security check=No; Linker, Advanced, Entry Point=main http://social.msdn.microsoft.com/Forums/hi-IN/vclanguage/thread/e2ea62c3-beb3-47a4-8963-60b799e3375a
- commented out headers in main.cpp except 'using namespace std' and #include - results in cascading and snowballing error from functions that referencing those headers
- I deleted everything in main.cpp except test code and excluded all source files except main.cpp; as expected it worked, so a small step in the right direction. The problem must be with one of the header files.
- create new project with Win32 Windows application template http://social.msdn.microsoft.com/Forums/ar-SA/vcgeneral/thread/105a366f-c38d-4c1c-9278-eca64589e7ca and http://social.msdn.microsoft.com/Forums/zh/Vsexpressvc/thread/341780c2-162e-4b36-9402-283c0cf7c0ac
have not tried and suspect that these also will not work:
- use int main() (not sure what they mean, file name or main function name) http://social.msdn.microsoft.com/Forums/zh/Vsexpressvc/thread/341780c2-162e-4b36-9402-283c0cf7c0ac
- using cmake to build on windows 7 x64 http://hdf-forum.184993.n3.nabble.com/error-LNK2019-unresolved-external-symbol-main-referenced-in-function-tmainCRTStartup-td3138042.html
why am I getting this error and what is the solution?
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 doesint main(int argc, char** argv)
no
tchar.h
necessaryand here is the same answer in Wikipedia Main function
In my case, it's because I accidentally removed (not deleted) thestdafx.h
andtargetver.h
files in the Header Files section.Add these files back to Header Files and the problem is solved.I had these:
I just need to comment that (by prepending
//
) and it's good.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 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.
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 !
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.