Author Topic: Purpose of projects  (Read 5187 times)

Offline spoofer

  • Multiple posting newcomer
  • *
  • Posts: 15
Purpose of projects
« on: October 23, 2005, 05:46:16 pm »
Projects in Code::Blocks are used quite differently then in other IDE (AFAIK). Here projects are used for nothing more then to tell where to place object/dependency files, while targets are used to tell which options to use when compiling and linking. Note this: you specify executable name for projects, but linking flags for target. Which means that each projects needs it's targets (no target reusing). Personally I find this way to be much better:

Options used for build =
  global
+ project specific   (source files, minimal compiling and linking flags)
+ target specific    (optimization, debugging ...)


For example, this way Code::Blocks source would have projects for tinyXML, wxDoctIt, SDK, while targets would be Release, Debug, Profile.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Purpose of projects
« Reply #1 on: October 23, 2005, 06:43:14 pm »
Hmm... actually you don't specify an executable name per project, but per target.

I find the way Code::Blocks handles things a lot easier than for example how Visual Studio does (I assume you did not mean to compare to Dev-CPP or Relo which are rather poor at handling projects).

On a large project, you would have one workspace and 20 project files using Visual Studio. One project file for every library, part, or executable that you want to build, with optional inter-project dependencies.

Code::Blocks uses one project file for everything and just defines one target for every component, this is a lot simpler and easier to follow. All dependencies are in one file, too.

You can very well work like this to get to your debug/release builds:

A workspace is just a convenient collection of projects.
A project holds together everything that makes "one product" or "one product suite". Change the optimization/debug flags here, all targets will inherit them (unless they explicitely override them). This is for example important if you use "dangerous" tuning parameters like regparm which generate non-ABI compatible code. With the VS approach, your code would crash and burn.
A target defines every "entity" which may be built separately. This may be a shared library, a static library, a plugin, a tool, or two different versions of the main program (a full version and crippleware version, for example).

It is different from how MS does it, true, but is it worse? A matter of taste I'd say :)
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline takeshi miya

  • Lives here!
  • ****
  • Posts: 1487
Re: Purpose of projects
« Reply #2 on: October 23, 2005, 07:57:09 pm »
Mm, yes, it's a matter of taste, it would depend on what you're used.

For version post-1.0 (compiler revamping), I would suggest a poll in this case

Offline hcye

  • Multiple posting newcomer
  • *
  • Posts: 20
Re: Purpose of projects
« Reply #3 on: October 23, 2005, 10:53:15 pm »
Is it possible to associate a file only to a target?

For example, I have many small files each with its own main() --- they are not part of the project but for unit tests only. I have been doing this in a pretty dumb way --- whenever I need to run a test, I add the file to project, and when it's done I remove it. It would be great if I can create a target for each test, and associate a test file with it, without causing multiple main() conflict.

Is there a way to do this? Thanks in advance!

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: Purpose of projects
« Reply #4 on: October 23, 2005, 11:03:48 pm »
In project properties, where you setup the targets, there's a list of the files inside the project with a checkbox next to each. Each checked file belongs to the target.
So, yes you can do it.
Be patient!
This bug will be fixed soon...

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Purpose of projects
« Reply #5 on: October 23, 2005, 11:04:06 pm »
This is exactly what targets are good for :)

And the good thing is you can even build several of them at the same time and have each one produce an executable with a distinct name.

If you have only one file though, then you are off easier by using the "Compile current file" from the menu bar.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Purpose of projects
« Reply #6 on: October 24, 2005, 07:29:58 am »
In another discussion we agreed to add "configuration" support for projects / targets after 1.0 is released. i.e. a target could have a "debug" or "release" configuration.

Offline spoofer

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Purpose of projects
« Reply #7 on: October 24, 2005, 07:40:56 am »
In another discussion we agreed to add "configuration" support for projects / targets after 1.0 is released. i.e. a target could have a "debug" or "release" configuration.

This is exactly what I needed. Great!

Offline hcye

  • Multiple posting newcomer
  • *
  • Posts: 20
Re: Purpose of projects
« Reply #8 on: October 24, 2005, 08:30:08 am »
It works great! I am new user and I am sure there are many gems like this in there!

(Just a small observation: The target file list includes both .cpp and .h files --- the latter can be excluded to shorten the list, I think.)

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: Purpose of projects
« Reply #9 on: October 24, 2005, 08:55:42 am »
(Just a small observation: The target file list includes both .cpp and .h files --- the latter can be excluded to shorten the list, I think.)

Didn't you hear? Precompiled headers are now supported! :D
Oh, and it's not only those two file types, but all files you add to your project. If you add images or textfiles or whatever else, they'll show up there too.