c++ - LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup -
i have following error lnk2019: unresolved external symbol _main referenced in function ___tmaincrtstartup,
there lot of threads relating error none of solutions worked me. and, none explained why error here.
i tried:
- wwinmaincrtstartup entry point in linker properties http://social.msdn.microsoft.com/forums/en/vclanguage/thread/14e85604-6929-4707-a22e-8cdf596926a6
- set linker "windows" (same thread above)
- right click on solution name->add->existing item->file main (same thread 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' , #include - results in cascading , snowballing error functions referencing headers
- i deleted in main.cpp except test code , excluded source files except main.cpp; expected worked, small step in right direction. problem must 1 of header files.
- create new project win32 windows application template http://social.msdn.microsoft.com/forums/ar-sa/vcgeneral/thread/105a366f-c38d-4c1c-9278-eca64589e7ca , http://social.msdn.microsoft.com/forums/zh/vsexpressvc/thread/341780c2-162e-4b36-9402-283c0cf7c0ac
have not tried , suspect these not work:
- use int main() (not sure mean, file name or main function name) http://social.msdn.microsoft.com/forums/zh/vsexpressvc/thread/341780c2-162e-4b36-9402-283c0cf7c0ac
- using cmake 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 getting error , solution?
what project type? if it's "win32 project", entry point should (w)winmain
. if it's "win32 console project", should (w)main
. name _tmain
#defined either main
or wmain
depending on whether unicode defined or not.
if it's dll, dllmain
.
the project type can seen under project properties, linker, system, subsystem. either "console" or "windows".
note entry point name varies depending on whether unicode defined or not. in vs2008, it's defined default.
the proper prototype main either
int _tmain(int argc, _tchar* argv[])
or
int _tmain()
make sure it's 1 of those.
edit:
if you're getting error on _tchar, place an
#include <tchar.h>
if think issue 1 of headers, go properties of file main(), , under preprocessor, enable generating of preprocessed file. compile. you'll file same name .i extension. open it, , see if unsavory happened main() function. there can rogue #defines in theory...
edit2:
with unicode defined (which default), linker expects entry point wmain(), not main(). _tmain has advantage of being unicode-agnostic - translates either main or wmain.
some time ago, there reason maintain both ansi build , unicode build. unicode support sorely incomplete in windows 95/98/me. primary apis ansi, , unicode versions existed here , there, not pervasively. also, vs debugger had trouble displaying unicode strings. in nt kernel oses (that's windows 2000/xp/vista/7/8/10), unicode support primary, , ansi functions added on top. ever since vs2005, default upon project creation unicode. means - wmain. not keep same entry point name because parameter types different. _tchar #defined either char or wchar_t. _tmain either main(int argc, char **argv) or wmain(int argc, wchar_t **argv).
the reason getting error @ _tmain
@ point because did not change type of argv
_tchar**
.
if you're not planning ever support ansi (probably not), can reformulate entry point as
int wmain(int argc, wchar_t *argv[])
and remove tchar.h
include line.
Comments
Post a Comment