Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » multiple main functions within one C project(multiple definition of main)
multiple main functions within one C project [message #1047145] Mon, 22 April 2013 17:20 Go to next message
Mackie M is currently offline Mackie M
Messages: 2
Registered: April 2013
Junior Member
Hello, I'm new to C eclipse. I use eclipse for java programs and found it very easy to create new classes within one project but now working on C. I would like to know how do I create multiple main programs within one project just as I could while running java. I have a C book and use youtube and I'm always creating new programs but would like to keep all organized under one C project. If I try to run a second main program I will get an error such as multiple definition of main. I guess I can create a new project for every tutorial/chapter but that option doesn't seem appropriate so I'd like to keep my projects organized just as could when working with Java.

Any help would be highly appreciated.

Re: multiple main functions within one C project [message #1047620 is a reply to message #1047145] Tue, 23 April 2013 08:56 Go to previous messageGo to next message
Arash Java is currently offline Arash Java
Messages: 3
Registered: April 2013
Junior Member
Why do you need mpultiple main-function?? it's not possible in c to have more than 1 main-function. you could use preprocessor directives like "#ifdef" to compile just one main-function at the time. an switch to another main-funtion by changing the condition.
But its not a good programing style.
Re: multiple main functions within one C project [message #1047892 is a reply to message #1047145] Tue, 23 April 2013 16:10 Go to previous messageGo to next message
Nobody Mising name is currently offline Nobody Mising name
Messages: 72
Registered: July 2010
Member
Mackie M wrote on Mon, 22 April 2013 17:20
I guess I can create a new project for every tutorial/chapter but that option doesn't seem appropriate so I'd like to keep my projects organized just as could when working with Java.

Internal CDT builder is primitive and can't do what you want because one project can have only one target. But you can always switch to external building via makefile or custom commands. So it is possible for example to use a single makefile with several different targets (executables). A convenient way to generate such makefile can be using CMake.
Re: multiple main functions within one C project [message #1050482 is a reply to message #1047145] Sat, 27 April 2013 04:15 Go to previous messageGo to next message
Edzard Egberts is currently offline Edzard Egberts
Messages: 57
Registered: July 2009
Member
Mackie M schrieb:
> Hello, I'm new to C eclipse. I use eclipse for java programs and found
> it very easy to create new classes within one project but now working on
> C. I would like to know how do I create multiple main programs within
> one project just as I could while running java. I have a C book and use
> youtube and I'm always creating new programs but would like to keep all
> organized under one C project. If I try to run a second main program I
> will get an error such as multiple definition of main. I guess I can
> create a new project for every tutorial/chapter but that option doesn't
> seem appropriate so I'd like to keep my projects organized just as could
> when working with Java.
> Any help would be highly appreciated.

Why not renaming them? Like main_test1(), main_test2() and calling them
from a single main, maybe using a menu. The menu could wrap the
funktions and provide an input of parameters, also telling about return
value.
Re: multiple main functions within one C project [message #1052870 is a reply to message #1050482] Tue, 30 April 2013 16:05 Go to previous message
Mackie M is currently offline Mackie M
Messages: 2
Registered: April 2013
Junior Member
I guess to be more specific I should add more details. While using java I could create a new class every time I started a new tutorial and ran each of them separately UNDER the same project. I would like to implement the same when working with C. I've done some research and it seems the only option is to create a targeted makefile with target files of its own. It seems C language is much older than expected. Or the last thing to do is to simply run every single tutorial/program under the main program which means I would not be able to save any other programs except for main which will be used to run the program.

Thanks for your help guys I really appreciate it.
Previous Topic:Empty build_files variable
Next Topic:how can I read protect my STM32F4 with eclipse + openOCD JTAG ?
Goto Forum:
  


Current Time: Fri Apr 18 14:18:48 EDT 2014

Powered by FUDForum. Page generated in 0.10887 seconds