Solved

Header Errors LNK2019, LNK1120 - Unresolved Externals

Posted on 2016-10-25
4
473 Views
Last Modified: 2016-10-26
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
{
public:
	Cat(int initialAge);
	~Cat();
	int GetAge() const { return itsAge; }
	void SetAge (int age) { itsAge = age; }
	void Meow() const { std::cout << "Meow.\n"; }
private:
	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;
}

Cat::~Cat()
{
}

int main()
{
	Cat Frisky(5);
	Frisky.Meow();
	std::cout << "Frisky is a cat who is " << Frisky.GetAge() << " years old.\n";
	Frisky.Meow();
	Frisky.SetAge(7);
	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!
0
Comment
Question by:blossompark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 32

Assisted Solution

by:phoffric
phoffric earned 125 total points
ID: 41859508
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:
Meow.
Frisky is a cat who is 5 years old.
Meow.
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.
0
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 125 total points
ID: 41859520
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).

https://msdn.microsoft.com/en-us/library/windows/desktop/ff381406(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633559%28v=vs.85%29.aspx
0
 
LVL 34

Accepted Solution

by:
sarabande earned 250 total points
ID: 41859922
you could try to change the project properties at menu

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

and choose Subsystem 'Console'.

Sara
0
 

Author Closing Comment

by:blossompark
ID: 41860069
Thank you all so much. I followed sarabande's advice and it's working perfectly now.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question