Reputation: 13
I have no background knowledge about programming, only experience I have is a little html coding in school. I literally started 2 days ago learning c++ and currently learning input and output streams, don't even understand debugging yet. I started a Visual Studio Project and wrote a second program, simple hello world, just like in the first. But this time, error occurred, _main is already defined in the .obj of the first program. What does this mean, what is the problem, how can I counter it and keep on working? Error LNK2005 _main I looked up the error code and understood nothing let alone found out how to fix it. Easy answers please. Thanks in advance
Program:
#include "pch.h"
#include <iostream>
using namespace std;
int main() {
cout << "Hello World2" << endl;
return 0;
}
Upvotes: 1
Views: 1766
Reputation: 1
Create a new project and paste your code in the new file and check. Execution of a program starts from main() method in every programming language, so can't have more than one main() method in the single program."Error LNK2005 _main" occurs when you define main() method more than ones.
Upvotes: 0
Reputation: 2699
If you have two files (.cpp) in your visual studio project each containing a main
or _tmain
function, link will fail because there can only be one main
function defined.
Rename all other main
function and you'll be fine.
Upvotes: 1