Multiple definition of main() /function()

Hi, I am using eclipse cdt, it is a managed c++ project, I have added a second x.cpp file and pasted some code and main function, now the compiler is using the same make for both of them, how to go around this?

thx
TheSilverBulletAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Infinity08Commented:
Create a new project for the other file, and that should work better :)
0
TheSilverBulletAuthor Commented:
nope I like to have more than one classe each with its main, that was dump easy in MS visual studio!
0
Infinity08Commented:
>> that was dump easy in MS visual studio!

You can only have one main in each project.

You can have multiple classes though, but again : only one main.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

evilrixSenior Software Engineer (Avast)Commented:
>> You can only have one main in each project
Just to expand on this, The function 'main', when defined int he global namespace is the entry point for the application. An application can only have one entry point, if the compiler finds more than one entry point the code is malformed and the compiler will generate an error. A project is a conceptual container for all resources and files that are used to generate an application, so if you have more than one main in a project you will have duplicated entry points.

It is perfectly legal; however, to define main in other namespaces. I would; though, advise against this as it will make for confusing code. Note, this only applies to C++, in C you don't have a concept of namespaces, but since you are referring to classes I presume you are referring to C++.
namespace
{
	void main(){} // This is legal, it's in an anonymous namespace
}
 
namespace SomeNS
{
	void main(){} // This is legal, it's in a named namespace
}
 
int main(){} // Entry point -- the one and only!!!
 
int main(){} // Not legal, already defined!!!
             // Not that even if this is in a different translation
             // unit this is still not legal!

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TheSilverBulletAuthor Commented:
Maybe I didnt make it clear, in VS one could add a classe with main on the fly (not necessarly to a project), just for probing something, that is the goal, scratching. but with eclipse everything is difficult, and buggy! I spent several ours for integrating a computer vision library, and at end could not use the debugger...
0
TheSilverBulletAuthor Commented:
and guess what? most of the problems because my workspace path had a space!! kinda c:\documents and settings...
0
Infinity08Commented:
If you want to debug your code, you can just run it in a debugger. No need to add a main or anything like that.
0
evilrixSenior Software Engineer (Avast)Commented:
>> Maybe I didnt make it clear, in VS one could add a classe with main on the fly (not necessarly to a project)
Was my post above, that explained you can have as many mains as you like but only 1 global, not clear enough? The same principle as shown in namespaces in my example also extends to classes (since classes are really just a special type of namespace -- honest).

To be honest I am not really seeing what the problem is here, maybe you could post an example that doesn't work for analysis? I suspect your observations on "main" are a red herring... this would not affect your ability to invoke and use the debugger (assuming the come compiles).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

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.