Header Errors LNK2019, LNK1120 - Unresolved Externals

Hello all.

I'm trying to create a simple header and implement it in a cpp file, but I am experiencing the following error messages.

LNK2019 unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
LNK1120 1 unresolved externals

Here is the code for my header.

#include <iostream>

class Cat
	Cat(int initialAge);
	int GetAge() const { return itsAge; }
	void SetAge (int age) { itsAge = age; }
	void Meow() const { std::cout << "Meow.\n"; }
	int itsAge;

Open in new window

Here is the code for the cpp file I am trying to compile.

#include "Cat.h"

Cat::Cat(int initialAge)
	itsAge = initialAge;


int main()
	Cat Frisky(5);
	std::cout << "Frisky is a cat who is " << Frisky.GetAge() << " years old.\n";
	std::cout << "Now Frisky is " << Frisky.GetAge() << " years old.\n";
	return 0;

Open in new window

Both have been copied directly from a book, and try as I might I can't see any mistakes in my transcription.

Many thanks in advance!
Who is Participating?
sarabandeConnect With a Mentor Commented:
you could try to change the project properties at menu

Projects - Properties - [All Configurations] - Configuration Properties - Linker - System - SubSystem

and choose Subsystem 'Console'.

phoffricConnect With a Mentor Commented:
Since I didn't see anything wrong with your code either, I created an empty project in VS 2015 Community edition. Using your code unaltered, I built/ran it and got this output:
Frisky is a cat who is 5 years old.
Now Frisky is 7 years old.

Open in new window

If you create a new  empty project in Visual Studio, you should be able to build with no problems. Just avoid creating a Win32 Project.
evilrixConnect With a Mentor Senior Software Engineer (Avast)Commented:
The problem is that you've probably created a Windows project rather than a Command line project. The entry point for Windows projects is WinMain and not main. The main function already exists inside the Windows code framework and this then calls WinMain as the application entry point (hence, it's complaining about WinMain not existing when called from main).

blossomparkAuthor Commented:
Thank you all so much. I followed sarabande's advice and it's working perfectly now.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.