Home > Backend Development > C++ > Why Am I Getting the 'Error LNK2019 unresolved external symbol _main' in my Windows Program?

Why Am I Getting the 'Error LNK2019 unresolved external symbol _main' in my Windows Program?

DDD
Release: 2024-11-17 21:10:02
Original
227 people have browsed it

Why Am I Getting the

Error: Unresolved External Symbol "_main"

Problem Description

You encounter the following error when compiling a Windows program:

Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
Copy after login

Explanation

This error indicates that the linker cannot find the _main function, which is the entry point for a Windows program. This can occur when the linker is not able to link against the correct library or module that defines _main.

Solution

To resolve this error, check the following:

1. SubSystem Setting:

Open the project properties and ensure that the following settings are correct:

  • Configuration PropertiesLinkerSystemSubSystem: Set to Windows.

2. Linker Options:

Verify the linker options in Configuration PropertiesLinkerGeneral:

  • Additional Library Directories: Include any necessary directories where required libraries reside.
  • Additional Dependencies: Link against the appropriate libraries, typically kernel32.lib.

Sample Code with Main Function

For clarity, here is a sample code that includes a main function:

int main() {
  // Your code goes here
  return 0;
}
Copy after login

Additional Notes

  • Visual Studio projects usually link against the **_mainCRTStartup function in the **msvcrt dynamic-link library (DLL).
  • If you are using a non-Visual Studio compiler, you may need to specify the _main function explicitly.
  • Ensure that your project's source code contains a valid main function definition.
  • If the problem persists, consider rebuilding the project or cleaning the solution and rebuilding.

The above is the detailed content of Why Am I Getting the 'Error LNK2019 unresolved external symbol _main' in my Windows Program?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template