


Why am I getting the \'error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup\' error in Visual Studio?
Nov 02, 2024 pm 06:10 PMUnresolved 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:
- Open your project in Visual Studio.
- Go to Project -> Properties.
- In the Properties dialog box, select Configuration Properties -> Linker -> System.
- Under Subsystem, select Console.
- 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!

Hot Article

Hot tools Tags
