Home  >  Article  >  Backend Development  >  Why Do I Get the LNK2019 Error: \"unresolved external symbol _main\" in C ?

Why Do I Get the LNK2019 Error: \"unresolved external symbol _main\" in C ?

Linda Hamilton
Linda HamiltonOriginal
2024-11-04 02:02:30513browse

Why Do I Get the LNK2019 Error:

Addressing the LNK2019: unresolved external symbol error in C

In the realm of C programming, the dreaded LNK2019 error can often leave developers perplexed. This error arises when the linker fails to locate an external symbol named _main during the compilation process.

Within the provided code, the implementation of a sequence class raises this error. While the code appears to be modular and type-safe, the fundamental problem lies in the absence of a defined main function elsewhere in the project.

To remedy this error, consider the following steps:

  • Define a separate main function in another source file. This function should be the entry point of the program and typically takes the form:
<code class="cpp">int main() {
  // Program logic goes here
  return 0;
}</code>
  • Ensure that the main function is declared and defined in the header file and source file, respectively.

In Visual Studio, if you encounter this error even with a defined main function, the following workaround may prove helpful:

  1. Navigate to Project -> Properties.
  2. Click on Configuration Properties.
  3. Expand Linker and select System.
  4. Under SubSystem, select Console.

This modification instructs the linker to expect a console application executable.

Once these steps are implemented, the linker should successfully resolve the external symbol reference, allowing the program to compile and execute seamlessly.

The above is the detailed content of Why Do I Get the LNK2019 Error: \"unresolved external symbol _main\" in C ?. 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