LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

unresolved external symbol _main referenced in function int __cdecl invoke_main(void)
unresolved external symbol c++
unresolved external symbol winmain 16 referenced in function int __cdecl invoke_main(void)
unresolved external symbol void __cdecl
unresolved external symbol __cdecl
unresolved external symbol winmain 16 referenced in function tmaincrtstartup c++
main obj error lnk2019: unresolved external symbol
msvcrtd.lib(exe_main.obj) error lnk2019

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?

What is your project type? If it's a "Win32 project", your entry point should be (w)WinMain. If it's a "Win32 Console Project", then it should be (w)main. The name _tmain is #defined to be either main or wmain depending on whether UNICODE is defined or not.

If it's a DLL, then DllMain.

The project type can be seen under project properties, Linker, System, Subsystem. It would say either "Console" or "Windows".

Note that the entry point name varies depending on whether UNICODE is defined or not. In VS2008, it's defined by default.

The proper prototype for main is either

int _tmain(int argc, _TCHAR* argv[])

or

int _tmain()

Make sure it's one of those.

EDIT:

If you're getting an error on _TCHAR, place an

#include <tchar.h>

If you think the issue is with one of the headers, go to the properties of the file with main(), and under Preprocessor, enable generating of the preprocessed file. Then compile. You'll get a file with the same name a .i extension. Open it, and see if anything unsavory happened to the main() function. There can be rogue #defines in theory...

EDIT2:

With UNICODE defined (which is the default), the linker expects the entry point to be wmain(), not main(). _tmain has the advantage of being UNICODE-agnostic - it translates to either main or wmain.

Some time ago, there was a reason to maintain both an ANSI build and a Unicode build. Unicode support was sorely incomplete in Windows 95/98/Me. The primary APIs were ANSI, and Unicode versions existed here and there, but not pervasively. Also, the VS debugger had trouble displaying Unicode strings. In the NT kernel OSes (that's Windows 2000/XP/Vista/7/8/10), Unicode support is primary, and ANSI functions are added on top. So ever since VS2005, the default upon project creation is Unicode. That means - wmain. They could not keep the same entry point name because the parameter types are different. _TCHAR is #defined to be either char or wchar_t. So _tmain is either main(int argc, char **argv) or wmain(int argc, wchar_t **argv).

The reason you were getting an error at _tmain at some point was probably because you did not change the type of argv to _TCHAR**.

If you're not planning to ever support ANSI (probably not), you can reformulate your entry point as

int wmain(int argc, wchar_t *argv[])

and remove the tchar.h include line.

LNK2019: unresolved external symbol _main referenced in function , msvcrt.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup. I'm using MS VC++  Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

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.

Linker Error: LNK2019: unresolved external symbol _main refe , So here's another thread about the infamous ___tmainCRTStartup unresolved external symbol. Yes, it's about SDL again, but it's with a twist  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. unresolved external symbol _main referenced in

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)

Visual C++ >>error LNK2019: unresolved external symbol _main , Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup MSVCRTD.lib(crtexe.obj) I am trying to  unresolved external symbol _main referenced in function ___tmainCRTStartup. 27. LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

If you have a "Win32 project" + defined a WinMain and your SubSystem linker setting is set to WINDOWS you can still get this linker error in case somebody set the "Additional Options" in the linker settings to "/SUBSYSTEM:CONSOLE" (looks like this additional setting is preferred over the actual SubSystem setting.

MSVCRTD.lib(crtexe.obj) :symbol _main referenced in function ___ , Posted: Visual C++ Language, error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup MSVCRTD.lib, Top  Hi Wayne, thanks for the support, I have verified that also, for both the builds its WINDOWS only. What puzzles me more is now is the second query, i.e I have a return FALSE as the only statement inside ht Winmain() in the existing code (due to which I suspect), the exe which is created doesn't show any visible output (in the Release built).

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;

error LNK2019: Error 1 error LNK2019: unresolved external symbol , MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main Duration: 1:23 Posted: Dec 31, 2013 To resolve this external reference, the application must link with the import library (.LIB file) provided by the maker of the DLL. The import library only contains code to load the DLL and to implement calls to functions in the DLL. Finding an external function in an import library informs the linker that the code for that function is in a DLL.

unresolved external symbol _main referenced in function ___ , Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup MSVCRTD.lib. This happens if you're  A dynamic-link library (DLL) is an executable file that acts as a shared library of functions. Dynamic linking provides a way for a process to call a function that is not part of its executable code. The executable code for the function is located in a DLL, which contains one or more functions that are compiled, linked, and stored separately

Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup MSVCRTD.lib. Error 2 fatal error LNK1120: 1 unresolved  Ok, resolved it. My bad, a typo in the command line meant the created .obj file was not named correctly, thus the missing link.

1>LIBCMTD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup. The code is taken from the “My first  Hello, I'm a student trying to write an app to produce a spectrogram from vorbis files. In effect, I'm trying to intercept the MDCT coefficients from the stream before they are transformed into PCM and output the result as an image much like how spectrograms are produced with the short-time FT.

Comments
  • Do you have a int main(char** argv, int argc) function?
  • @Linuxios, it's "int main(int argc, char** argv)" (the order is wrong in your prototype)
  • @BlakBat: Thanks. Sorry. I don't even work on Windows anyway, but that 's the signature everywhere. Doh.
  • I tried changing int main() to int _tmain() and there is still a lnk2019 error
  • int _tmain(int argc, _TCHAR* argv[]) results in error C2061: syntax error : identifier '_TCHAR'; I tried variations of this with int main(int argc, char** argv) that returned the intial lnk2019 error
  • if I remove all the headers with the exception of #include <iostream> and comment out all but a test line of text then this compiles, so it seems like the issue is in one of the header files - what is the process to track-down an issue in a header that results in the lnk2019 main error
  • If you're getting an error on _TCHAR, place an #include <tchar.h> Also, see my edit.
  • that worked. I did not make to connection with #include <tchar.h> given in some of the threads I referenced and int _tmain(int argc, _TCHAR* argv[]); can you explain what is going on functionally - what was wrong with int main(), why all this other stuff?
  • make sure include tchar.h
  • This worked for me also. In fact it worked when subsystem is 'not set' also.
  • I bet this is the problem in a lot of cases.
  • Ever heard of wmain()?
  • This answer is too specific to yourself. Since main is not misspelled anywhere in the OP's question, there's no reason to assume this is the problem.
  • OP didn't show any source code, he just stated the error. I had the same error today, but later realized that i misspelled the word main, so after correcting it the error disappear ..