I have NEVER had this experience before while coding my past assignments. For some reason, I keep getting this error that says

error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

.

I looked it up on google and people have been saying it's because I should've created a windows APPLICATION program instead of a windows CONSOLE. BUT THEY ARE WRONG! I've ALWAYS done windows console and this has NEVER popped up! Why is this happening to me?! This is my final project and I can't even get started because of this error!

I've TRIED creating a windows APPLICATION program and copy/pasted the same source code/header files and tried building it, BUT a different error pops up then. So I looked up that error on google and people have been saying that it's because I haven't created a windows CONSOLE application! So these errors keep putting me in circles!!!

How do I get rid of this stupid error?! Please help.
To explain in detail here's what I did to create this project:
1) Create a windows console application >> empty project
2) Created a new header file and pasted in the appropriate code from a different header
3) Created a new source file and pasted in the appropriate code from a different source
**I did save and move these files to its appropriate places, yet the error still occurs.

Here is my header and implementation code (I have more but I wanted to see if these two could even build correctly--and they can't)

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

class Customer
{
public: 
	//Constructor
	Customer();

	//Mutators
	void setTitle(string titl);
	void setName(string firstNam, string middleNam, string lastNam);
	void setAddress(string add, string cit, string stat);
	void setZip(string zip);
	void setPhone(string phone);

	//Accessors
	string getTitle();
	string getFirstName();
	string getMidName();
	string getLastName();
	string getStreetAdd();
	string getCity();
	string getState();
	string getZip();
	string getPhone();

	//Output
	void displayLabel(ostream &out);
	void displayPhoneListing(ostream &out);

	//Operators
	bool operator ==(Customer& rightOperand) const;

private:
	string title, firstName, middleName, lastName, streetAdd, city, state, zipCode, phoneNum;
};
//Customer imple

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include "Header1.h"

using namespace std;

Customer::Customer()
{
}

void Customer::setTitle(string titl)
{
	title = titl;
}

void Customer::setName(string firstNam, string middleNam, string lastNam)
{
	firstName = firstNam;
	middleName = middleNam;
	lastName = lastNam;
}

void Customer::setAddress(string add, string cit, string stat)
{
	streetAdd = add;
	city = cit;
	state = stat;
}

void Customer::setZip(string zip)
{
	zipCode = zip;
	if(zipCode.length() > 5)
		zipCode.insert(5, "-");
}

void Customer::setPhone(string phone)
{
	phoneNum = phone;
	phoneNum.insert(0, "(");
	phoneNum.insert(4, ")");
	phoneNum.insert(8, "-");
}

string Customer::getTitle()
{
	return title;
}

string Customer::getFirstName()
{
	return firstName;
}

string Customer::getMidName()
{
	return middleName;
}

string Customer::getLastName()
{
	return lastName;
}

string Customer::getStreetAdd()
{
	return streetAdd;
}

string Customer::getCity()
{
	return city;
}

string Customer::getState()
{
	return state;
}

string Customer::getZip()
{
	return zipCode;
}

string Customer::getPhone()
{
	return phoneNum;
}

void Customer::displayLabel(ostream &out)
{
	out << endl << title << " " << firstName << " " << middleName << " " << lastName << endl;
	out << streetAdd << endl;
	out << city << " " << state << " " << zipCode << endl;
}

bool Customer::operator ==(Customer& rightOperand) const
{
	if(firstName == rightOperand.firstName && middleName == rightOperand.middleName && lastName == rightOperand.lastName)
		return true;
	return false;
}

Dani AI

Generated

Short answer: the linker had no program entry point because the project did not contain a translation unit that defines main (or the appropriate Windows entry point). As pointed out, adding the source file that contains the entry function fixes the problem.

Quick checklist for this class of linker error:

  • Make sure one source file in the project defines a valid entry point. For a console app a minimal example is:
int main()
{
    return 0;
}

For GUI apps use the appropriate WinMain/wWinMain signature instead.

  • If you copied files into the project folder manually, use "Add > Existing Item" in Solution Explorer so the files are actually part of the project. Files placed on disk but not added to the project are not compiled/linked.

  • Verify the file is not "Excluded From Build" (file Properties) and that the correct configuration/platform (Debug/Release, x86/x64) is being built.

  • Check Project Properties -> Linker -> System -> SubSystem matches the entry point (Console vs Windows). Also ensure Linker -> Advanced -> Entry Point is empty unless you intentionally specified a custom entry point.

  • If using the generic _tmain macro or wide-character variants, confirm your character-set setting and headers match the signature you implemented. If you use precompiled headers, include them correctly or disable them for the file.

A clean rebuild after fixing the above usually resolves the error. For authoritative references see Microsoft documentation on the linker subsystem and the linker error pages: Linker /SUBSYSTEM option and Linker Tools Error LNK2019.

This thread’s resolution was that adding the missing main fixed the build (as confirmed by ).

Recommended Answers

All 2 Replies

Where is the *.cpp file that contains main()? Check your project files to make sure one of the *.cpp files contains that function. You said you created an empty project -- my guess is that you forgot to add main()

Oh....wow.

That did the trick..................................I feel like a fool.... :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.