I keep experiencing this error!

Hello!

This is my first post on this forum, so I'm going to try and make this as helpful as I can. I recently installed CodeBlocks so I could get started in C++. I was able to build my first "Hello World" file fine, but on my next one, I seem to be having some issues.

My file is called "MoreText.cpp". It's in the exact same directory as HelloWorld.cpp. The code will be shown below, but basically I'm experiencing a problem in which the following is shown when I try to build and run the program:

1
2
3
In function 'main'
Multiple definition of 'main'
First defined here


And then it points to the line in which I have 'int main()' as my code. I don't know what the problem is. I've tripled checked the code for any typos, and can't spot any. I'll provide the code for the entire file below, but if you could please help me with this, I'll be sincerely grateful.

Thanks!

1
2
3
4
5
6
7
8
9
#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}
I think what has most likely happened to you is that Code::Blocks thinks it is all part of the same project, and is trying to compile everything as the same program -- meaning two source files, each with a main().

Whenever using an IDE, always always make sure that you start a new project for every different set of sources, and never keep sources in the same directory as another program's sources.

That will keep problems like this from happening.

Hope this helps.
Topic archived. No new replies allowed.