Author Topic: Tutorial for person new to IDEs  (Read 7460 times)

Offline LowWaterMark

  • Single posting newcomer
  • *
  • Posts: 7
Tutorial for person new to IDEs
« on: August 05, 2008, 12:23:59 pm »
I recently installed Code::Blocks (codeblocks-8.02mingw-setup.exe) and am teaching myself C language.  I am absolutely new to programming and the use of compilers/IDEs.

I did not want to post this but after several days of trying to do it on my own the closest thing I could find to a tutorial was the Wiki WxSmith tutorial on creating GUI apps in Code::Blocks for the wxWidgets platform.

I desperately need something more fundamental.

Can anyone point me to a tutorial that (simply) explains the use of Code::Blocks.  I very much appreciate the Code::Blocks user manual but I found its 64 pages a bit advanced for me, presupposing knowledge and vocabulary that I do not possess.

All ideas and suggestions will be sincerely appreciated.

Take care.
« Last Edit: August 05, 2008, 12:36:09 pm by LowWaterMark »
"In music the passions enjoy themselves." -Nietzsche
"Architecture is music, frozen in time and space." -Goethe
"Time and space . . . have no separate existence from matter." -Einstein  "It began as a mistake." -Charles Bukowski

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Tutorial for person new to IDEs
« Reply #1 on: August 05, 2008, 01:13:07 pm »
If you're only just learning C and want nothing else, here's your tutorial:
1. click on "create a new project" on the "start here" page
2. select "console application"
3. select "C"
4. type in a name for your project
5. an editor has opened, type in your C code, whatever you want
6. press the blue gear to compile, and the green wedge to run your program
6a. alternatively, press the gear-with-wedge symbol to do both

Later, much later, when you write more complex programs that have more than a single file, add them to the project (right-click on the manager window to the left), so they're compiled as well. Everything that should go into one program goes into one project (so, for another program, make another project).
Still later, you will find that the more complex your programs get, the more mistakes you make, and the harder it is to find them. That's when you will want to learn how to use the debugger. Read the manual then.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Tutorial for person new to IDEs
« Reply #2 on: August 05, 2008, 02:08:02 pm »
CUNY CodeBlocks Student Manual
http://www.sci.brooklyn.cuny.edu/~goetz/codeblocks/codeblocks-instructions.pdf

Takes some time to load, but is a very good beginners manual.

« Last Edit: August 05, 2008, 02:14:02 pm by Pecan »

Offline LowWaterMark

  • Single posting newcomer
  • *
  • Posts: 7
Re: Tutorial for person new to IDEs
« Reply #3 on: August 05, 2008, 07:22:17 pm »
Wonderful -very wonderful.  Hey Pecan, the CUNY Brooklyn .pdf is just what I need following the straightforward tutorial courtesy of Thomas.  I appreciate your time.

One follow-up question.  I was surfing the YouTube videos on code::blocks and one of the contributors said that it was a mistake to install the IDE in Program Files (as the default installation settings has you do).  It was suggested that it go up a level so as to be a root folder [C:/CodeBlocks], or else "you will get yourself into trouble later".  No elaboration.  Mine is already installed as per the default instructions in my Program Files folder.

Any reason to uninstall and move it closer to the bone?
"In music the passions enjoy themselves." -Nietzsche
"Architecture is music, frozen in time and space." -Goethe
"Time and space . . . have no separate existence from matter." -Einstein  "It began as a mistake." -Charles Bukowski

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Tutorial for person new to IDEs
« Reply #4 on: August 05, 2008, 07:26:39 pm »
Once upon a time, there was an issue with spaces in pathnames, not with Code::Blocks, but with one of the MinGW tools (I forgot which one). So, if people installed MinGW into the Code::Blocks folder, and that one inside "Program Files", it would eventually bite them. To the best of my knowledge, this isn't an issue any more with recent versions.
Code::Blocks as such doesn't care where it is installed. You can move the folder around as you like, too... no need to uninstall/reinstall anything.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Jan van den Borst

  • Multiple posting newcomer
  • *
  • Posts: 99
Re: Tutorial for person new to IDEs
« Reply #5 on: August 05, 2008, 10:00:43 pm »
Once upon a time, there was an issue with spaces in pathnames, not with Code::Blocks, but with one of the MinGW tools (I forgot which one).

Was it not the windows resource compiler windres.exe?

Offline JGM

  • Lives here!
  • ****
  • Posts: 518
  • Got to practice :)
Re: Tutorial for person new to IDEs
« Reply #6 on: August 06, 2008, 05:19:51 am »
Was it not the windows resource compiler windres.exe?

Yep! that was the one  :)

Offline LowWaterMark

  • Single posting newcomer
  • *
  • Posts: 7
Re: Tutorial for person new to IDEs
« Reply #7 on: August 06, 2008, 09:42:57 am »
Thanks.  Pecan, I am halfway through the 64p CUNY Brooklyn tutorial you linked me to and it's very well written.  I'm starting to get the big picture.  Again, thank you.

Hey, Thomas!  I followed your instructions (6 posts above) by the numbers but Step 5 never happened.  The text editor didn't open.  I named it "Thomas" in the wizard and the path to the project was created it in C:\Program Files\CodeBlocks\trials\Thomas\Thomas.cbp as anticipated.  But the text editor is greyed out.  Thomas comes up in the tree as a Project Folder with a single "Sources" Sub-folder containing only one file, the ubiquitous "Hello World" source file entitled main.c but no Thomas.c and nowhere to type.

If I go File>New>Empty File and agree to the prompt to name and save the file Thomas.c under the current project, "Thomas", I then receive the following prompt:
Quote
Select the targets this file should belong to:
   1. debug
   2. release

And now I'm becoming confused.

I know the fault is mine.  Any idea what I am doing wrong?  Erasing the text of main.c in the code::blocks editor and changing its name in Windows Explorer (which I did) seem a tad crude and probably isn't what the designers intended for me to do.

Thoughts?
« Last Edit: August 06, 2008, 10:58:39 am by LowWaterMark »
"In music the passions enjoy themselves." -Nietzsche
"Architecture is music, frozen in time and space." -Goethe
"Time and space . . . have no separate existence from matter." -Einstein  "It began as a mistake." -Charles Bukowski

Offline LowWaterMark

  • Single posting newcomer
  • *
  • Posts: 7
Re: Tutorial for person new to IDEs
« Reply #8 on: August 06, 2008, 02:20:07 pm »
. . . and while I'm at it, why does code::blocks call for this standard library on line 2:
#include <stdlib.h>

a request never issued in the other 5000 iterations of this holy grail of introductory *.c source code that I have read.
"In music the passions enjoy themselves." -Nietzsche
"Architecture is music, frozen in time and space." -Goethe
"Time and space . . . have no separate existence from matter." -Einstein  "It began as a mistake." -Charles Bukowski

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Tutorial for person new to IDEs
« Reply #9 on: August 06, 2008, 04:44:19 pm »
Thomas comes up in the tree as a Project Folder with a single "Sources" Sub-folder containing only one file, the ubiquitous "Hello World" source file entitled main.c but no Thomas.c and nowhere to type.

you can call your sources whatever names you want - the name of the output binaries can be totally different from the names of the sources (to see this, go to project->properties->build targets). it is a convention to use main.c as the name of the main entry point of applications (i.e. that file will contain the main function). you don't have to obey that convention (and most gui apps do not because the main function is often defined in the gui library). You do have to ensure that only one source file in each build target (see below) has a main function.

Quote
If I go File>New>Empty File and agree to the prompt to name and save the file Thomas.c under the current project, "Thomas", I then receive the following prompt:
Quote
Select the targets this file should belong to:
   1. debug
   2. release

First some background on CB projects: Each project can have multiple targets, by default the codeblocks console app wizard creates a debug and release target for you but each project can have arbitrarily many targets. targets are the binaries (and supporting files) that you want to create, typically an executable or a library. The code::blocks build system lets you define what sources are used, what compiler options are set and numerous other build instructions for each target in a project. Normally the only difference between a debug and release target is the compiler options used (the former is built with debugging symbols) but there can also be source code differences (e.g. extra logging in the debug target etc).

Now, when you create a new file, you will be asked if you want to add it to a project, then you can choose which targets to add it to. for a typical debug/release setup, it makes sense to add the file to both projects.

. . . and while I'm at it, why does code::blocks call for this standard library on line 2:
#include <stdlib.h>

a request never issued in the other 5000 iterations of this holy grail of introductory *.c source code that I have read.

stdlib defines some basic system and memory handling routines. you don't need it to build the helloworld app, that's just how CBs helloworld template is.
« Last Edit: August 06, 2008, 04:45:58 pm by dmoore »

Offline LowWaterMark

  • Single posting newcomer
  • *
  • Posts: 7
Re: Tutorial for person new to IDEs
« Reply #10 on: August 07, 2008, 10:56:47 am »
Thanks dmoore.  I sincerely appreciate your reply and of course, your time.

One thing however - the main.c file isn't coming up for me as a blank entry point into the project (did I install Code::Blocks incorrectly?).  It's the source code for the "Hello World" thing.  Is there any way to create a New Project with the Console Wizard without having the main.c file ("Hello World") included by default in the Source File folder?  It may be irrelevant, but there must be a way to get rid of it unless I want every project I create in Code::Blocks IDE to say "Hello World" when I execute it.

More importantly, the function for telling the machine where to start reading in the main.c source file reads int main().  Not just main() but int main().  The int part of this main() function line confuses me.  Does it have something to do with the source file's name also being main.c?  Do I have to get it out of the trials folder in the default path C:\Program Files\CodeBlocks\trials\*.  At any rate, I get error messages for "multiple definitions of main()" when I try to write a new source file, I imagine because the main.c "Hello World" source file is within every project I try to create in Code::Blocks.

I can imagine my portfolio in a few years:  200 some-odd projects that start out by saying "Hello World" 8) . . .

Seriously, I know it is me, not the program.  Nonetheless, I am stumped.  Code::Blocks is famous for being easy.  What pray tell could I be doing wrong?
« Last Edit: August 07, 2008, 12:00:42 pm by LowWaterMark »
"In music the passions enjoy themselves." -Nietzsche
"Architecture is music, frozen in time and space." -Goethe
"Time and space . . . have no separate existence from matter." -Einstein  "It began as a mistake." -Charles Bukowski

Offline LowWaterMark

  • Single posting newcomer
  • *
  • Posts: 7
Re: Tutorial for person new to IDEs
« Reply #11 on: August 07, 2008, 01:24:47 pm »
Allow me to distill down my own confusion.  The Alpha and the Omega:

main()
{
return 0;
}

meaning:  start executing code here and return to DOS here.  What's the meaning of inserting int in front of the main() Function?

FWIW, I'm using "Absolute Beginner's Guide to C", Second Edition, by Greg Perry.  In 365 pages it never mentions prefixing the main() Function with int.  Does this int tell the compiler to be heads up for an integer type of value to be returned from the program when it ends (i.e. the zero in return 0)?

Can anyone id the locus of my confusion?  Thx.
« Last Edit: August 07, 2008, 01:47:06 pm by LowWaterMark »
"In music the passions enjoy themselves." -Nietzsche
"Architecture is music, frozen in time and space." -Goethe
"Time and space . . . have no separate existence from matter." -Einstein  "It began as a mistake." -Charles Bukowski

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Tutorial for person new to IDEs
« Reply #12 on: August 07, 2008, 03:33:50 pm »
Thanks dmoore.  I sincerely appreciate your reply and of course, your time.

One thing however - the main.c file isn't coming up for me as a blank entry point into the project (did I install Code::Blocks incorrectly?).  It's the source code for the "Hello World" thing.  Is there any way to create a New Project with the Console Wizard without having the main.c file ("Hello World") included by default in the Source File folder?  It may be irrelevant, but there must be a way to get rid of it unless I want every project I create in Code::Blocks IDE to say "Hello World" when I execute it.

The default template is just a helpful stub. It gives you a quick way to test that the compiler/IDE are functioning correctly before you start coding. It is trivial to delete the parts of the file that you don't want or to just remove the file from the project in its entirety (right click in the project manager window -> remove from project)

if you want to change the default project files you have at least a couple of options:
1. you could edit main.c in [Your CB Installation Dir]\share\CodeBlocks\templates\wizard\console\c
2. create your own project wizard based on other wizards (take a look at the contents of [Your CB Installation Dir]\share\CodeBlocks\templates\wizard\). There's probably stuff in the wiki on how to do this

Also keep in mind if you are only writing simple one-file programs, you don't need to create a project at all. Close all open projects and create an empty file. Write your program in that file, save it. Then you will be able to compile and run it from CB

Quote
More importantly, the function for telling the machine where to start reading in the main.c source file reads int main().  Not just main() but int main().

In ANSI C (i.e. standard C) main always returns an int. That int is the error code returned to the calling process (i.e. the program that called your program). The convention is to return zero if the program terminates normally.

Quote
At any rate, I get error messages for "multiple definitions of main()" when I try to write a new source file, I imagine because the

as I said, you can have at most one main in each build target (this is the way the C programming language works and isn't a CB restriction). thus, if you want to put main in a different file from main.c then you either have to remove main.c or at least delete the main function from main.c

it seems that many of your questions are programming questions as opposed to CB questions. your needs might be better met on a dedicated programming board/forum (e.g. comp.lang.c (through google groups) codeguru or gamedev). we can only give you very limited programming help on this board because the topics must be CB related.
« Last Edit: August 07, 2008, 04:02:48 pm by dmoore »

Offline LowWaterMark

  • Single posting newcomer
  • *
  • Posts: 7
Re: Tutorial for person new to IDEs
« Reply #13 on: August 07, 2008, 08:32:56 pm »
Sorry for posting in the wrong arena.  Ironically your response helped me out quite a lot with the big picture architecture behind code::blocks.  I'm departing these wilds and looking into the forums you suggested.  Thanks for the links and thanks for your time.
"In music the passions enjoy themselves." -Nietzsche
"Architecture is music, frozen in time and space." -Goethe
"Time and space . . . have no separate existence from matter." -Einstein  "It began as a mistake." -Charles Bukowski