Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » More Than One Main() In The Project(More Than One Main() In The Project)
More Than One Main() In The Project [message #1787248] Tue, 22 May 2018 17:38 Go to next message
Mukesh Lekhrajani is currently offline Mukesh LekhrajaniFriend
Messages: 12
Registered: May 2018
Junior Member
Hi Members -

I have been using Eclipse for 4+ years but only for JAVA & J2EE, never for C/C++.

For C/C++ coding, i used notepad++ and command line compiling using borland 5.5

I just have downloaded the Eclipse IDE for C/C++. I created the project and added 1 C source file and executed the Hello-World program by configuring GCC & C++ (using MinGW) and it worked properly.

now, when i am adding another C source file in the same project, and i have written a small program to write something else on screen using printf().

it gives compilation error and tells "more than 1 'main' found" and does not compile the program.. it fails.

Please give solution.

- Mukesh Lekhrajani
Re: More Than One Main() In The Project [message #1787463 is a reply to message #1787248] Fri, 25 May 2018 17:27 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
it means just what it says: you have more than one defined function called 'main'.
You need to eliminate all but one of them.

A common cause is trying to build more than one executable in a project.
Although it's possible to do, you would need to write your own makefile.
The Eclipse/CDT makefile builder won't handle that.
If that's what you've tried to do then separate them into different projects.

GCC usually tells you where the first occurrence is but, if not,
you can do a file search for 'main'.

Re: More Than One Main() In The Project [message #1787467 is a reply to message #1787463] Fri, 25 May 2018 18:01 Go to previous message
Ken Caron is currently offline Ken CaronFriend
Messages: 3
Registered: August 2013
Junior Member
I was looking to do something similar. We are starting a project and have several "newbie" eclipse and c coders. My plan was to create one project they could pull from our GIT repository and then have several C exercises. It has been a very log time since I've done a makefile, but I might do that.

For now, I have used different configuration (one for each main):

    Select c/c++ file
    Right click and select properties
    Open C/C++ General>Paths and Symbols
    Use the "Manage Configurations" button to create a new configuration based on Debug (default)
    Provide a name and description based on file selected


The only problem with this is that main will replace the <project>.exe file. Use the build ("hammer" icon), and select the configuration for the main to build.
Previous Topic:Disable info prints in "Problems window
Next Topic:Can't compile C++ inside eclipse
Goto Forum:
  


Current Time: Wed Apr 24 22:26:30 GMT 2024

Powered by FUDForum. Page generated in 0.02434 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top