Home >Backend Development >C++ >Why am I getting the 'Error LNK2019 unresolved external symbol _main' error in my C project?

Why am I getting the 'Error LNK2019 unresolved external symbol _main' error in my C project?

Linda Hamilton
Linda HamiltonOriginal
2024-11-16 00:04:03198browse

Why am I getting the

Error: Unresolved External Symbol "main"

Problem

The build process fails with the following error:

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

Cause

This error occurs when the project lacks a properly defined main function. In a Windows program, the operating system expects an entry point function named main to be defined.

Solution

To resolve this error, ensure that your project contains a main function that meets the following requirements:

  • It must be defined as the entry point of the program.
  • It must follow the syntax: int main(int argc, char *argv[])
  • It must be defined in a source file that is included in the project build.

Detailed Answer

In the provided code, the main function is missing. Adding the following code to the project will resolve the issue:

int main()
{
    // Your application code here...
    return 0;
}

Additional Notes

  • Make sure that the linker settings in your project properties are configured correctly. Specifically, the "SubSystem" option under "Linker" -> "System" should be set to "Windows."
  • If you are using a non-Windows platform, the entry point function may be named differently. Consult the documentation for your platform for the correct entry point function name.

The above is the detailed content of Why am I getting the 'Error LNK2019 unresolved external symbol _main' error in my C project?. 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