Author Topic: Projects Files Verses Code Files  (Read 4069 times)

Offline beaker353

  • Single posting newcomer
  • *
  • Posts: 2
Projects Files Verses Code Files
« on: June 04, 2011, 09:47:49 am »
I'm new to C++ and CodeBlocks so please bear with this rather novice question.  I am slowly going through a 1100+ page Ivor Horton's ANSI C++ book to get a decent foundation of C++ to help with my electrical engineering technology studies.  Hardware microcontrollers pretty much run near everything these days and they are based solidly on C++ architecture and concepts.  Installation of CodeBlocks was easy and I have the link to the compiler working with basic "hello world" style apps.

I'm getting the hang of how CodeBlocks works, but without more programming knowledge (coming soon...) I'm a little lost trying to figure out the file organization scheme CodeBlocks uses.  I tried the manual, but it's a little over my head for the moment and I couldn't find a answer in the forum search.  I've figured out that I create a "C/C++ source" file through "new from template" to create a file to hold my code.  And I figured out that I have to have a "project" open in order to send code to the compiler.  What are projects files verses code files and how this is all supposed to work in harmony.  Thanks!

- EM

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Projects Files Verses Code Files
« Reply #1 on: June 04, 2011, 10:32:31 am »
well look at a project like this :

* a program
                      OR
* a static/dynamic library providing functionality to reuse in different programs

* ...


Let's focus on the "program" : a program will consist out of several files. You could put everything in 1 source file, but that is no really manageable (you could consider this just like having 1 closet in your house, where you put all your stuff [not rally handy right ;-) ] )
So when you have organized your code in different source files, they need to be build together to create the program. When you call the compiler by hand you specify 1 file at a time. Now this is where the project comes in, when CodeBlocks is going to build the project it will compile every source file from the project in turn (calling several times the compiler : 1 call per source file), and then in the end it calls the linker to link all the compiled files together into the program executable.

So why a project :
- clean organization of your code
- you can specify settings on the project which are then applied towards the compiler for all source files (like defines)

One more little info : within a project you can have several 'target's, typical use is : debug and release target. Typically the debug target is not optimized by the compiler and contains debug symbols so you can debug the program.The release target will be optimized (for speed or code size); since you want the thing to run as fast as possible ;-)


Offline beaker353

  • Single posting newcomer
  • *
  • Posts: 2
Re: Projects Files Verses Code Files
« Reply #2 on: June 05, 2011, 07:42:16 pm »
Thanks for the guidance.  Projects and code file makes sense now.  Follow up question...  I noticed there are a host of project presets, which I gather has various settings optimized for what form the project ends up as.  As I'm stumbling though learning the C++ language and coding principals, which project preset should I be using for the simple coding principals I'll be working on for a while?  "Console" project preset seems to be an obvious choice?  Thanks!

- EM

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Projects Files Verses Code Files
« Reply #3 on: June 05, 2011, 07:54:54 pm »
yes, start with console project