Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Why only one main per a C-project
Why only one main per a C-project [message #214208] Thu, 17 April 2008 14:16 Go to next message
Eclipse UserFriend
Originally posted by: markus.innerebner.net

Hi all,

Can somebody tell me, if there is a way to specify within CDT a C
project that contains several c files, where each file has a main function.

thanks a lot

Markus
Re: Why only one main per a C-project [message #214237 is a reply to message #214208] Thu, 17 April 2008 15:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Axel.Howind.htp-tel.de

Why would you want to do that in the first place?

If your project is a program - you can't.
If your project is a library - you can't.
It's a C restriction.

The only reasonable thing would be to have multiple programs and/or
libraries created during the build process. If so, there are 2 alternatives:

1) create one project per program/library - you can still have them all
in the same workspace.

2) write a makefile on your own.

Axel

markus innerebner schrieb:
> Hi all,
>
> Can somebody tell me, if there is a way to specify within CDT a C
> project that contains several c files, where each file has a main function.
>
> thanks a lot
>
> Markus
Re: Why only one main per a C-project [message #214284 is a reply to message #214237] Fri, 18 April 2008 02:00 Go to previous messageGo to next message
Justin Clift is currently offline Justin CliftFriend
Messages: 16
Registered: July 2009
Junior Member
Axel Howind wrote:
> Why would you want to do that in the first place?
>
> If your project is a program - you can't.
> If your project is a library - you can't.
> It's a C restriction.

No, I'm thinking he means to have a single project (i.e. folder), with
several separate applications developed/built in there.

I remember looking for how to do this when I first started using Eclipse
+ CDT too, and felt (at the time) that Eclipse was pretty brain damaged
to not have the flexibility for it. Heh. ;->

Makes me kind of wonder though, would it be possible to actually do this
by having a different C++ Build Configuration for each of the apps?

Configuring each of those configurations with a different build artifact?

i.e. Configuration 1: "Snowball"
Artifact -> "snowball"
Source File -> snowball.c (with it's own main())

Configuration 2: "Icestorm"
Artifact -> "icestorm"
Source File -> icestorm.c (with it's own main())

<etc>

?

Regards and best wishes,

Justin Clift


> The only reasonable thing would be to have multiple programs and/or
> libraries created during the build process. If so, there are 2
> alternatives:
>
> 1) create one project per program/library - you can still have them all
> in the same workspace.
>
> 2) write a makefile on your own.
>
> Axel
>
> markus innerebner schrieb:
>> Hi all,
>>
>> Can somebody tell me, if there is a way to specify within CDT a C
>> project that contains several c files, where each file has a main
>> function.
>>
>> thanks a lot
>>
>> Markus


--
Salasaga - Open Source eLearning IDE
http://www.salasaga.org
Re: Why only one main per a C-project [message #214312 is a reply to message #214237] Fri, 18 April 2008 09:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: fwein.lse.eei.uni-erlangen.de

> 2) write a makefile on your own.
We have currently three mains, and it makes perfectly sense as it is
based on
the same code (main app, tool app, test app)

We use cmake to create makefiles and I find cmake pretty nice - works
smoothly with eclipse,
there is even a editor plugin.

Fabian
Re: Why only one main per a C-project [message #214319 is a reply to message #214312] Fri, 18 April 2008 10:04 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: markus.innerebner.inf.unibz.it

Fabian Wein wrote:
>> 2) write a makefile on your own.
> We have currently three mains, and it makes perfectly sense as it is
> based on
> the same code (main app, tool app, test app)
>
> We use cmake to create makefiles and I find cmake pretty nice - works
> smoothly with eclipse,
> there is even a editor plugin.
>
> Fabian

Ok, great thanks for all your answers
So I will use cmake.

Markus
Re: Why only one main per a C-project [message #214385 is a reply to message #214208] Fri, 18 April 2008 18:32 Go to previous messageGo to next message
Ray Hurst is currently offline Ray HurstFriend
Messages: 121
Registered: July 2009
Senior Member
markus innerebner wrote:
> Hi all,
>
> Can somebody tell me, if there is a way to specify within CDT a C
> project that contains several c files, where each file has a main function.
>
> thanks a lot
>
> Markus
I thought the correct answer is this:

CDT default is to expect one program per project (application or
library). You can set dependencies of the project on other projects.
For example, if you have an application that depends on a home built
library you need to setup two projects, one for the library and one for
the application. You then make the application dependent on the library.

If you require the project to create several applications and libraries
and handle all of the dependencies then you need to write your own
makefile. CDT allows this also.
Ray
Re: Why only one main per a C-project [message #215104 is a reply to message #214385] Tue, 29 April 2008 00:26 Go to previous messageGo to next message
ian scott-fleming is currently offline ian scott-flemingFriend
Messages: 4
Registered: July 2009
Junior Member
I've been trying to figure this out myself.

If it can't be done in eclipse with a managed make project, then what is
the Make view for, and all the options in the make view such as "add make
target".

Seems like they are designed to allow multiple targets in one project
without having to write the make file oneself. Unfortunately, I can't
figure out how they are supposed to work, to do just that task.
Re: Why only one main per a C-project [message #215183 is a reply to message #215104] Tue, 29 April 2008 18:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ag.xxx.com

ian scott-fleming wrote:

> I've been trying to figure this out myself.

> If it can't be done in eclipse with a managed make project, then what is
> the Make view for, and all the options in the make view such as "add make
> target".

> Seems like they are designed to allow multiple targets in one project
> without having to write the make file oneself. Unfortunately, I can't
> figure out how they are supposed to work, to do just that task.

Make View is rather to support existing makefile. If you have one, you can
run its targets from inside Eclipse.
Re: Why only one main per a C-project [message #215338 is a reply to message #214284] Thu, 01 May 2008 21:11 Go to previous message
Eclipse UserFriend
Originally posted by: dont.use.eml

Justin Clift wrote:
> Axel Howind wrote:
>> Why would you want to do that in the first place?
>>
>> If your project is a program - you can't.
>> If your project is a library - you can't.
>> It's a C restriction.
>
> No, I'm thinking he means to have a single project (i.e. folder), with
> several separate applications developed/built in there.
>
> I remember looking for how to do this when I first started using Eclipse
> + CDT too, and felt (at the time) that Eclipse was pretty brain damaged
> to not have the flexibility for it. Heh. ;->
>
> Makes me kind of wonder though, would it be possible to actually do this
> by having a different C++ Build Configuration for each of the apps?
>
> Configuring each of those configurations with a different build artifact?
>
> i.e. Configuration 1: "Snowball"
> Artifact -> "snowball"
> Source File -> snowball.c (with it's own main())
>
> Configuration 2: "Icestorm"
> Artifact -> "icestorm"
> Source File -> icestorm.c (with it's own main())
>
> <etc>
>
> ?

Unfortunately, that seems to break some functionality such as the C/C++
Indexer, the "//TODO" parser, etc.

I might be missing something - but whenever I "exclude" a file/folder
from the Release/Debug default build configurations, they become
effectively non-project files and I miss such functionality as mentioned
above.
Previous Topic:Invalid project path: Duplicate path entries
Next Topic:gdb doesn't like paths with spaces (mingw/win32) (repost)
Goto Forum:
  


Current Time: Fri Apr 19 13:58:03 GMT 2024

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

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

Back to the top