Home > Backend Development > C++ > Why Does My C Code Produce 'error LNK2019: unresolved external symbol _WinMain@16' and How Do I Fix It?

Why Does My C Code Produce 'error LNK2019: unresolved external symbol _WinMain@16' and How Do I Fix It?

Barbara Streisand
Release: 2024-12-19 02:32:32
Original
166 people have browsed it

Why Does My C   Code Produce

Resolving "error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup"

In attempt to execute basic code, two errors surface:

#include <iostream>
#include <string>
using namespace::std;

template <class Type>
class Stack
{
public:
    Stack (int max):stack(new Type[max]), top(-1), maxsize(max){}
    ~Stack (void) {delete []stack;}
    void Push (Type &val);
    void Pop (void) {if (top>=0) --top;}
    Type& Top (void) {return stack[top];}
    //friend ostream& operator<< (ostream&, Stack&);
private:
    Type *stack;
    int top;
    const int maxSize;
};

template <class Type>
void Stack <Type>:: Push (Type &val)
{
    if (top+1<maxsize)
        stack [++top]=val;
}
Copy after login

Errors:


MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup


Resolution

This error originates from a linker problem. To address it:

  1. Open your project properties in Visual Studio.
  2. Navigate to Linker > System.
  3. Under SubSystem, change the setting from Windows (/SUBSYSTEM:WINDOWS) to Console (/SUBSYSTEM:CONSOLE).

This should resolve the linker error and allow you to execute your code successfully.

The above is the detailed content of Why Does My C Code Produce 'error LNK2019: unresolved external symbol _WinMain@16' and How Do I Fix It?. 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