Home >Backend Development >C++ >Why am I getting the \'error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup\' error in Visual Studio?

Why am I getting the \'error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup\' error in Visual Studio?

Linda Hamilton
Linda HamiltonOriginal
2024-11-02 18:10:03783browse

Why am I getting the

Unresolved External Symbol _main: Resolving the Linker Error

The error "error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup" occurs when the linker cannot find the main() function in your program. This is a critical error that prevents the program from running.

Cause of the Error

In Microsoft Visual Studio, the default subsystem type is set to Windows (GUI). However, if your program uses the console for input and output operations, you need to change the subsystem type to Console. The linker expects the main() function to be the entry point for a console application, so if the subsystem type is incorrect, it cannot find the main() function and generates the error.

Solution

To resolve this error, follow these steps:

  1. Open your project in Visual Studio.
  2. Go to Project -> Properties.
  3. In the Properties dialog box, select Configuration Properties -> Linker -> System.
  4. Under Subsystem, select Console.
  5. Click OK to save the changes.

Explanation

By changing the subsystem type to Console, you instruct the linker to generate a console executable. This executable will now have the required entry point (main()) for a console application, and the linker will successfully resolve the external symbol.

Note:

  • If you have a main() function but are still getting the error, check for spelling or syntax errors.
  • If you do not have a main() function, add one to your program.
  • Ensure that your program has the correct include directives for necessary libraries (e.g., stdio.h for console input/output).

The above is the detailed content of Why am I getting the \'error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup\' error in Visual Studio?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn