Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » multiple definitions of main issue( How to make Eclipse handle multiple definitions of main?)
multiple definitions of main issue [message #1059440] Sat, 18 May 2013 14:03 Go to next message
James private is currently offline James privateFriend
Messages: 42
Registered: July 2009
Member
Eclipse is giving me the error " multiple definitions of main".
when I make my own makefile or use cmake, I do not get these errors. I have a test project where I create multiple source files each with it's own main() function. The goal is to have the compiler create a separate and distinct binary executable for each of these. my make files have no problems doing this, how do I get Eclipse to do it? Or is Eclipse inferior in this regard?
Re: multiple definitions of main issue [message #1059467 is a reply to message #1059440] Sun, 19 May 2013 09:44 Go to previous messageGo to next message
Joost Kraaijeveld is currently offline Joost KraaijeveldFriend
Messages: 273
Registered: July 2009
Senior Member
On 18-05-13 16:03, James Mising name wrote:
> Eclipse is giving me the error " multiple definitions of main".
> when I make my own makefile or use cmake, I do not get these errors. I
> have a test project where I create multiple source files each with it's
> own main() function. The goal is to have the compiler create a separate
> and distinct binary executable for each of these. my make files have no
> problems doing this, how do I get Eclipse to do it? Or is Eclipse
> inferior in this regard?
You cannot create an Eclipse "managed build" executable project with
multiple main functions. You could use a central main function that,
depending e.g. on command line arguments, runs the real separate main
functions.

Whether that is inferior is up to you, but as far as I know the C++
standard (3.6.1) requires exactly 1 main function per program (although
it is implementation defined for a freestanding environment). And an
Eclipse "managed build" executable project is for 1 executable ;-).

Joost


Cheers,

Joost
Re: multiple definitions of main issue [message #1059476 is a reply to message #1059440] Sun, 19 May 2013 11:53 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
You can create a BuildConfiguration for each main function. There you can define which main.cpp to include and which executable you want to create.
http://help.eclipse.org/juno/topic/org.eclipse.cdt.doc.user/reference/cdt_u_prop_all.htm


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: multiple definitions of main issue [message #1059506 is a reply to message #1059476] Mon, 20 May 2013 06:29 Go to previous messageGo to next message
Joost Kraaijeveld is currently offline Joost KraaijeveldFriend
Messages: 273
Registered: July 2009
Senior Member
On 19-05-13 13:53, Axel Mueller wrote:
> You can create a BuildConfiguration for each main function. There you
> can define which main.cpp to include and which executable you want to
> create.
> http://help.eclipse.org/juno/topic/org.eclipse.cdt.doc.user/reference/cdt_u_prop_all.htm

Could you elaborate on that a bit as I cannot see how this is actually
done? I suspect that you mean that I could use macro-like stuff to
define the correct main, but that still means that I can use only 1 main
per build and hence 1 program and not several main's an therefore
several programs.

Personally, I would like to be able to do exactly what the OP wants, but
I have to use Makefiles to do so.

Joost


Cheers,

Joost
Re: multiple definitions of main issue [message #1748151 is a reply to message #1059506] Sat, 19 November 2016 07:38 Go to previous message
dklovedoctor Mising name is currently offline dklovedoctor Mising nameFriend
Messages: 2
Registered: September 2011
Junior Member
You can always write down you own Makefile and use it instead of the automaticaly generated one:
http://stackoverflow.com/a/8107675/967564
Previous Topic:Latest Eclipse
Next Topic: Why Launching failed?
Goto Forum:
  


Current Time: Thu Apr 25 07:08:46 GMT 2024

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

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

Back to the top