0

I've been searching around for a solution and I came across this one: https://stackoverflow.com/a/12574400/13991027 I followed the steps but it still does not seem to work.

I have made projects in the past with VS and this is the first time I have gotten this error. My code is fairly short, so I don't think it is an error with the code. main.cpp:

#include <iostream>
#include "menu.h"

int main()
{
    int mode = menu();// 1 == easy, 2 == medium, 3 == hard
}

menu.h:

#ifndef MENU_H
#define MENU_H

int menu();

#endif

menu.cpp

#include <iostream>

int menu()
{
    // Store user input in mode choice
    std::string modeChoice;
    std::cout << "Please select one of the following to begin:\n";
    std::cout << "-Easy\n -Medium\n -Hard\n";

    // Check for correct input
    do
    {
        std::cout << "Enter a difficulty here:";
        std::cin >> modeChoice;
        for (int i = 0; i < modeChoice.length(); i++)
        {
            if (modeChoice[i] >= 'A' && modeChoice[i] <= 'Z')
            {
                modeChoice[i] += 32;
            }
        }
    } while (modeChoice != "easy" || modeChoice != "medium" || modeChoice != "hard");

    if (modeChoice == "easy")
    {
        return 1;
    }
    else if (modeChoice == "medium")
    {
        return 2;
    }
    else
    {
        return 3;
    }
}

Here is the output tab:

1>------ Build started: Project: project, Configuration: Debug Win32 ------
1>MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
1>C:\Users\bobb\Desktop\hangman\Debug\project.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "project.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
RudyGoburt
  • 291
  • 1
  • 11
  • There should be more information about the error then that. Did you check the Output Tab? If there is any please edit the question and add the exact text of the error messages. – drescherjm Aug 10 '20 at 16:56
  • Just edited the question – RudyGoburt Aug 10 '20 at 17:00
  • 1
    This means you created the wrong project type. You created a GUI project when you wanted a console based project. – drescherjm Aug 10 '20 at 17:01
  • 1
    Change the project type to 'console' (or manually override the entry point). See [error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup](https://stackoverflow.com/questions/6626397/error-lnk2019-unresolved-external-symbol-winmain16-referenced-in-function) for example. – dxiv Aug 10 '20 at 17:02
  • @drescherjm Ya you are right. Looks like he created a Win32 Windows app as the linker is searching for `WinMain` – Asesh Aug 10 '20 at 17:02
  • You can change the linker subsystem in your project settings. – drescherjm Aug 10 '20 at 17:03
  • Correct me if I'm wrong but I don't remember being given the choice of project type? When making this project I pressed file > Create new project from existing code – RudyGoburt Aug 10 '20 at 17:04
  • @dxiv Thanks. Followed the instructions on the post and it is working now. – RudyGoburt Aug 10 '20 at 17:06
  • For me in Visual Studio 2019. Its "Create New Project" then "Console App". With that said the options have changed a bit over the last few years since there are quite a few options now with all the cross platform development and other project types. – drescherjm Aug 10 '20 at 17:07
  • I am glad you have got your solution and thanks for your sharing, I would appreciate it if you mark them as answer and this will be beneficial to other community. – Barrnet Chou Aug 14 '20 at 05:56

0 Answers0