Home > Backend Development > C++ > body text

Why Am I Getting Error LNK2019: Unresolved External Symbol _main?

Mary-Kate Olsen
Release: 2024-11-02 20:57:30
Original
837 people have browsed it

Why Am I Getting Error LNK2019: Unresolved External Symbol _main?

Understanding Error LNK2019: Resolving External Symbol _main

The error message "error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup" indicates that the linker cannot resolve the definition of the main function. This function is the entry point for C applications.

In the provided code, the main function is declared in a separate header file (main_savitch_sequence.h). However, the header file only includes the declaration of main, without its implementation.

To resolve this error, you need to provide the implementation of main in the source file (sequence1.cpp). The implementation of main should look something like this:

<code class="cpp">#include "sequence1.h"

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

Once you have added the implementation of main, the linker should be able to resolve the external symbol and build the application without errors.

However, in some cases, even with the main function defined in the source file, you may still encounter the LNK2019 error. This can happen when using Visual Studio.

Visual Studio Specific Solution

If you are using Visual Studio, you can resolve the LNK2019 error by changing the SubSystem option in the project properties. Here's how:

  1. Right-click on the project in Solution Explorer.
  2. Select "Properties" from the menu.
  3. Navigate to the "Configuration Properties" section.
  4. Expand the "Linker" node.
  5. Click on the "System" tab.
  6. Change the "SubSystem" option to "Console."

Changing the SubSystem option tells the linker to use the appropriate entry point for a console application. This should resolve the LNK2019 error and allow you to build the project successfully.

The above is the detailed content of Why Am I Getting Error LNK2019: Unresolved External Symbol _main?. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!