Home

Code::Blocks Student Manual - Professor Langsam`s Home Page

image

Contents

1. K l M M MM g Add symbol File 10 Debugging windows d li Information d lz list Edit watches Opened Files l4 E main cpp 15 Attach to praeses Petach Send user command to debugger 19 cout lt z lt 4 endl el return 0 4 Execute the r WINDOWS 1252 Line 18 Calumn 1 Insert Read Write Z To determine how your program will function when calling functions such as z addem x y Step info Shift F7 can be selected from the Debug pull down menu 45 of 61 Projects finc lude lt iostream gt Be Workspace wing namespace std mum debug D i Sources int addenmiint int manen int addemiint a int b int c E ds rene s ata c ath satan oe return c E Ems Ems oy E UE Ec a m serenus eS T m nnan Opened Files UR main main cpp satan naan int x 5 ye Semet vtat anges nat 5 EH SSS et E z addenix y cout lt z lt lt endl pera SSS E Eu PEPER Baas s return 0 ener E us buses m 3 x 4 aa TE e a nanananans Sa The next step 1s line 9 46 of 61 I L cal variables EF Jnctian Arguments The arguments a and bare shown in the Watches window Notice that the local variable c which has not been set yet has a random value 47 of 61 main cpp debug Code Blocks 1 0
2. main cpp debug Code Blocks v1 0 E B x File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help oe y ID EE t FB c 3 Stop debugger sin int PO gt ie C3 L target OP SO d tretie b JJ Continue cr F ey Ll f main cE Ts Next line F7 s b X or 1 F Next instruction Alt F E G Workspace 2 T Step into Shift F7 3 Mig debug 4 18 Step out Ctrl Shift F7 a Sources s main cpp z Toggle breakpoint F5 7 yz Run to cursor a g Add symbol File 10 Debugging windows k n Information k ien Files list 13 Edit watches TEY Files l4 Attach to praeses main c 15 a Petach Send user command to debugger 19 coub lt z lt lt endl el return 0 4 Run program WINDOWS 1252 Line 18 Calumn 18 Insert Read Write Z The next step in debugging a program 1s to tell the program when to stop running so you can inspect the results To do this place the cursor over the line where you want your program to stop For example the cursor was placed at line 18 which is hidden behind the menu This 1s called a Breakpoint Now you can instruct the debugger to run the program up to the cursor s position line number 40 of 61 ti E Documents and Settings goetz My Documents debug debug exe 3 The program will generate a blank window It is blank since that program has yet to execut
3. For Mac OS X 10 4 you need to install Xcode Tools version 2 2 or later Download Code Blocks Uncompress the zip file and place CodeBlocks app where you like it The suggested location is Developer Applications or Applications Installation for Fedora 8 Linux Installing Code Blocks In a console window become root and then execute the following command yum install codeblocks 60 of 61 Running Code Blocks In the Applications Pull Down Menu go to Programming and click on Code Blocks IDE or Open a console window and then execute the following command codeblocks Installation for Ubuntu Linux Installation Instructions From http forums codeblocks org index php topic 5208 msg61085 htmlztmsg61085 1 Add the repositories to etc apt sources list Open the file with a graphical editor as root Paste the following line in a terminal gksu gedit etc apt sources list Paste this at the end codeblocks deb http 1gp203 free fr ubuntu gutsy universe wx widgets deb http apt wxwidgets org gutsy wx main Note Depending on what version of Ubuntu you are using in step 1 you may need to replace gutsy with feisty 2 To make sure your package system trusts these sources Add their keys Enter these two lines at the terminal wget q http lgp203 free fr public key O sudo apt key add wget q http apt wxwidgets org key asc O sudo apt key add And update the packages by entering the following
4. Ld d J bx Projects 1 finclude iostreaearm ge Workspace e using namespace std z 3 E d ena E int addemiint int _ m in cpp 6 lint addem int a int bi Y int c x ap c atb 10 ll return c LE I 13 Opened Files l4 int main main cpp 15 ii 16 int x 5 y 4 E 1 l8 z addemix vyi 15 cout lt 4 z endl 20 el return 0 2E I 23 2 E Document WINDOWS 1252 Line 19 Calumn 8 Insert Read Write Z This screen shows breakpoints on lines 9 and 19 but line 9 indicates that the code has executed to that point 56 of 61 main cpp debug Code Blocks 1 0 E c ni x File Edit Build Debug wx5mith Tools Plugins METERSE 2 Em 3 Stop debugger ee peni cb Cs 1 Build target Deb E T VEGAR pim i e View Search Project Settings Help anagemente main c Te Mext line FF d bx Projecks 1 F Next instruction Alt F EC Workspace 2 T step into shift F7 5 3 El Mg debug 4 X8 Step out Ctrl Shift F7 o Sources ooo main cpp z Toggle breakpoint F5 7 ue Run to cursor F4 B C 8 Add symbol File 10 Debugging windows d LL Information lz pen Files list Edit watches gt Opened Files 14 gt ae Attach bo process bee main cpp 15 Petach Send user command to debugger 15 4 couk zz g cc endl el return 0 Continue exe WINDOWS 1252 Line 19
5. File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help eS amp V E YE Start FS Hb R Stop debugger addemgint a int b int OP Shag Build target i P SO tt b E Continue cr X 0 eg lg SH BIEN tS main a e Mex line J X Projects 1 F Next instruction Alt F E Workspace 2 Ph Step into Shift F7 rj 3 Ei Mg debug 4 f Step out Ctrl shift F7 B Sources main cpp z Toggle breakpoint F5 7 M Run to cursor F4 B X X X O P P 8 Add symbol File 10 Debugging windows k Information k Edit watches Opened Files l4 Attach to process E main cpp 15 Petach Send user command to debugger 15 cout lt z s endl el return J 4 Execute ther WINDOWS 1252 Line 9 Column 1 Insert Read Write 5 To proceed to the next line of code select Next line from the Debug menu Pressing F7 is a useful keyboard shortcut and will become second nature as you become familiar with the system 48 of 61 T al Function Arguments The debug window reflects the change of c 49 of 61 main cpp debug Code Blocks 1 0 E O x File Edit View Search Project Build Debug weSmith Tools Plugins Settings Sl e ok i E tat EB 63 Stop debugger o b es m e Build targe
6. The debugger that you will use is part of an Open Source free IDE called Code Blocks which we have found easy to use and is described in these notes Code Blocks has a C editor and compiler It will allow you to create and test your programs from one easy to use application We hope these notes will assist you in making programming more enjoyable and help you develop better programming skills You may find additional information regarding Code Blocks at http www codeblocks org A complete manual for Code Blocks is available here http www codeblocks org user manual 3 of 61 Installation of Code Blocks Step 1 Download the Software In order to install the Code Blocks IDE as well as the MinGW compiler you must download it If you are using either Windows XP or Windows Vista download the installation programs from here http downloads sourceforge net codeblocks codeblocks 8 02mingw setup exe Save the file to your hard disk and remember its location Proceed to the next page in order to continue the installation If you are using Mac OS X or Linux please see Appendix I for installation instructions 4 of 61 Step 2 Install the Software Next open click on CodeBlocks install file and the CodeBlocks Setup will begin installing as follows O CodeBlocks Setup E O x Welcome to the CodeBlocks Setup Wizard This wizard will quide vau through the installation of CodeBlocks It is recommended that vau close all
7. Calumn 8 Insert Read Write 5 Selecting Continue from the Debugger menu will run the program till the next breakpoint 57 of 61 main cpp debug Code Blocks 1 0 File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help SRol AE SON UEEVS o es es e Build target Debug lE ue IM EAE iv 63 E i Projects jd b l finclude ziostream ge workspace Z using namespace std 3 a SA debu i int addemiint int UU main cpp 6 lint addem int a int bi Y int c zx o4 c atb 10 ll return c LE I TEUER l3 Opened Files l4 int maint main cpp 15 ii 16 int x 5 y z H 17 l8 z addemix wyi 13 cout lt lt z lt 4 endl 20 el return 0 fal fal 23 i 4 E Document WINDOWS 1252 Line 19 Column 1 Insert Read Write 5 Now the program stops at line 19 because the program reached the second breakpoint Press Ctrl F7 to continue Now the program runs till the end of the program because there are no further breakpoints to encounter 58 of 61 When you exit Code Blocks you may be presented with the following window TTT x 2 Workspace Default workspace is modified Do you want to save it No Cancel Say Yes to save the Workspace This saves settings of the workspace you are working on You now know the basics of how to use the compiler work with a project and use the debugger Good luck with your programming 59 o
8. History Deskto p Mv Documents hy Computer File name sample cpp work F Save as type C C files Cancel EZ PA My Me Give a name to the file Pick a name that is related to the content of the file Here it 1s called sample cpp C files need to be of the type cpp Press Save to save the file Multiple selection Select the targets this File should belong to v Debug v Release Deselect All Selected 2 Press Select All to have this file saved as both Debug amp Release targets Press OK when done A target is a type of compiled version You can work with a debug target which will allow you to test the program using a debugger A debug target will be large in size because it has extra information in it to allow you to test for errors A release target is smaller in size because it does not have the debugging information When you are ready to give other people such as your Instructor your finished program you should give them the release target 23 of 61 sample cpp First Program CodeBlocks 1 0 File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help SER SIS sit P Olas 0 b pS buld target bstug l EBT DOOS Projects Symbols EG Workspace Fag First Program Sources B main cpp sample cpp Opened Files Loading AStvlePlugin Aubtasave BYOGames CBProfiler CB Koders Class Wizard CodeCompletion CodeSnippets Code Sta
9. bring up a window so you can browse to where your files that you wish to add are Select any additional file you want to add and press Open The file will then be added to your project If you are creating a new file you can use the pull down File menu and open an empty file 21 of 61 First Program CodezBlocks 1 0 File Edit wiew Search Project Build Debug weSmith Tools Plugins Settings Help Mew Empty File Ctrl ShiFt M 4 Open Ctra Project Open default workspace Build target Recent projects File Recent Files Custom From user template Import project Ed Save Girls v Save as Save all Ales Ghr Shift 5 Save project Save project as Save project as user Eemplake Save all projects Ep UU XA Code Blocks Debug Save workspace as StylePlugin Qutosave BYOGames CBProfiler CB Koders if d CodeCompletion CodeSnippets CodeStatistics Compiler Glebe morera s Debugger FilesExtensionHandler DeyPakUpdater DragScroll ource Exporter HelpPlugin cbKevBinder ScriptedWizard Clase File Chri x Smith wxSmithfime wx Smikh Wwieard WwindawsxPLoakMFeel Glose all Files CEr ShiEE I arkup script Close project Close all projects E File New Empty file You will be asked if you want to add this file to the project Add file to project Choose Yes Code Blocks will ask for a file name to save the file as 22 of 61 Save file Save ihi E First Fragram de t C main cpp o Bra
10. lines on the terminal sudo apt get update sudo apt get upgrade 3 Install Code Blocks Enter the following line in the terminal sudo apt get install libcodeblocksO codeblocks libwxsmithlibO codeblocks contrib You are able to step 3 whenever you want you to get the latest nightly build You should see Code Blocks in the Programming Languages listing of your programs 61 of 61
11. other applications before skarting Setup This will make it possible to update relevant system Files without having to reboot your computer Click MexE to continue Cancel Click Next 5 of 61 O CodeBlocks Setup License Agreement Please review the license terms before installing CodeBlocks Press Page Down to see the rest of the agreement GA GENERAL PUBLIC LICENSE Version 3 29 June 200 Copyright C 2007 Free Software Foundation Inc http JJFsF argr gt Everyone is permitted to copy and distribute verbatim copies of this license document but changing it is not allowed Preamble The GNU General Public License is a Free copyleft license For software and other kinds of works IF you accept the terms of the agreement click I Agree to continue You must accept the agreement to install CodeBlocks Mullsart Install System v2 35 z Back Cancel Select I Agree O CodeBlocks Setup Choose Components Choose which Features of CodeBlocks vau want to install Check the components vau want to install and uncheck the components veu don t want to install Click Next to continue Select the type of instal SRS eee ea Or select the optional E3 Default install components vau wish ka E Contrib Plugins install L CB Share Config v MinGW Compiler Suite Description Space required 102 5MB Position your mouse ower a component to see i
12. the Press any key to continue message E Documents Hello worldt E Documents and Settings goetz Mu Documents First Program Notice that there are double quotes around the file name This is because there is a space in the name If 33 of 61 you execute this program by double clicking on it s icon the program would close right away That is because the pause statement is only done when you run your program in Code Blocks When you are done save all your files by pulling down the File menu and clicking on Save all files main cpp First Program Code Blocks v1 0 P IBl x File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help Mew E L R Open icErl o E maint int Open default workspace Recent projects Recent Files Import project include iostream gt gave Gtr 5 E d awe as nt mairi Crl ShifE 5 LI std cout lt lt Hello world std endl Save project return 0 Save project as Save project as user template Save all projects Save Workspace Save workspace as Close workspace je and version CHU gdb 6 3 EJ Close File Chi W l qoetz IYDOCU l FIRSTP l main cpp E5 Close all Files Ckrl 5hift w ished with status E Close project Close all projects 11 Insert Read Write 5 34 of 61 Now you can select to save the project main cpp First Program CodezBlocks 1 0 E Mew Open Ctrl O Open de
13. when you Compile your program you will have a Debug version available To compile a file means to take the instructions that you have written and translate it into machine code for the computer to understand 30 of 61 main cpp First Program CodezBlocks 1 0 E File Edit View Search Project Build Debug wx5mith Tools Plugins Settings Help ee S te gt amp OS u Ctrl F9 e a Compile current file CEri ShifE Fa miQ m gt Run Ctrl F 10 gt e m e Build TUE t5 Build and run F3 HE Ne TP S m 07 O g Rebuda Ctrl F11 Clean Projects Build workspace 2 4 3 Workspace Rebuild workspace Fag First Program Clean workspace Ne woe 63 Abort world lt lt std endl Errors d Select target k 7 Opened Files E main cpp Ej Untitled Export Makefile 3 Debugger Setting breakpoints Debugger name and version GNU gdb 6 3 At E DOCIHHE l gqgoetz MYDOCU l FIBSTP l main cpp 5 Debugger finished with status oO a ok E Build log y Build messages Compile curr WINDOWS 1252 Line 6 Column 11 Insert Read Write 5 Compile your file from the Build pull down menu by clicking on Compile current file Ctrl Shift F9 31 of 61 main cpp First Program Code Blocks 1 0 E B mi xl File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help ee amp gt E QS Bui Ctrl F9 EM Co
14. 8 z addemix wyi T cout lt 2 z lt 4 endl el return s E Document WINDOWS 1252 Line 3 Column 11 Insert Read Write 5 A breakpoint has been set at line 9 The red circle indicates that there is a breakpoint in the code 52 of 61 main cpp debug Code Blocks v1 0 E E m ojx File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help il Se olt x 5d LE Start E C3 Stop debugger i6 P Q DG puidtargetsoet JE continu addemfink a int b int ee l O nt main c Ts ext line ry 1 b X Projects I 4 Next instruction AILEY Fly Workspace 2 Th Step into shift F7 E Mg debug 4 4 Step out Gtr Shitty Sources ee main cpp a Toggle breakpoint F5 7 e Run to cursor F4 a g Odd symbol File 10 Debugging windows d 11 Information k db Edit watches Attach to process Petach 3 Opened Files ae main cpp 15 Send user command to debugger 19 coub lt z lt lt endl el return 0 4 Run current E WINDOWS 1252 Line 9 Column 11 Insert Read Write 5 The program is started by selecting from the Debug pull down menu Start This will run the program in the debugger until a breakpoint is encountered at which point the program will pause 53 of 61 main cpp debug Code Blocks 1 0 File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help oe 5 amp VIF S os 5 Eoo r
15. Code Blocks Student Manual Lawrence Goetz Network Administrator Yedidyah Langsam Professor and Theodore Raphan Distinguished Professor Dept of Computer and Information Science Brooklyn College of CUNY 2006 2008 Version 8 02 1 of 61 Table of Contents DAY GNU LOSI anos a soca ae ec e cto pg teeta cect atta ae taal aa mee Ue cM acter eps ee MEX a alae ienaeetiete 3 Installation of the Code Blocks IDE and the MinGW Compiler eeeeereeeee 4 US COMI ATOM Saca eonim dte Ea eT LU EN bM nieces eee cara T enced ee 8 PST PROC eR 12 Zxddineriles To x out wel x Cr ie tae ere ureter en nan ee er 20 DeDU S212 dq PLO Ot Acer Fisiassncaadacerticee E AEE 39 Appendix A Installing Code Blocks under Mac OS X and Linux esee 60 2 of 61 Introduction Through the aid of a compiler a program written in a computer language such as C is turned into machine code which is executed on the computer However going from an idea to a program that works successfully takes a lot of time and effort It may take several rewrites of code to get the program to work correctly To accomplish this students must learn a disciplined approach to organizing the code and learn how to trace their programs The purpose of this manual is to help the student develop the skills to organize program coding and develop sound techniques for finding and isolating errors Here you will learn how to trace the code step by
16. e any line that displays something 41 of 61 main cpp debug Code Blocks 1 0 3 cd E iol x File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help 1E Bg amp E A IE Start Fa ETO 3 Stop debugger an int 2 beoeue I target O P Sl O u tretie bt E Continue cr X 457 63 n al iuge mem n v main CE q Next line Fy bx Projects 1 F Next instruction Alt F EC Workspace 2 T step into shift F7 B 3 FE Mig debug 4 43 Step out Ctri Shift F7 e Sources I i main cpp E Toggle breakpoint F5 7 Mm Run to cursor F4 B E 8 Add symbol File Debugging windows Breakpoints Information k Call stack Open File X iz Edit watches CPU Registers F Of ened Files Disassermbl pen ai Attach bo Process l i bee main cpp 15 M Examine memory j etar l6 Running threads Send user command to debugger watches 15 cout lt z lt 4 endl el return 0 4 Watch variab WINDOWS 1252 Line 18 Calumn 1 Insert Read Write 5 To watch certain variables during the execution of the program you should open the Watches window This will show you the variables in your code This is accomplished by going to the Debug pull down menu and clicking on Debugging Windows and then Watches 42 of 6l ee Function Arguments n Ma arguments These are the watches that the debugger is displaying Notice that x amp y have the correct values Variable
17. f 61 Appendix A Installation of Code Blocks for Mac OS X and Linux If you are using the Mac OS you will need to do the following Pre Install steps Here is a step by step instruction file for setting up X11 and XcodeTools for the Mac 1 Make sure that X11 is installed in your system check in your Application menu If not you ll need to install it from your Mac OS disc o Insert the disc and find the optional packages installer open it check the X11 box and install from that o If you are using 10 1 through 10 3 you can download X11 from Apple 2 Install Developer Tools You may be able to skip this step if you are using Mac OS X 10 4 Tiger and have installed the Developer tools o Asatest open up xterm You cannot use terminal with Code Blocks xterm is part of X11 and that is why you ll need to have X11 installed o Run the command gcc If you get an error that there are no input files that means gcc exists and you are good to go If you get an error saying the command is not found you need to install the Developer Tools o If you need to install the Developer tools you can download them from Apple or you can install them from your Mac OS disc Locate the Xcode installer on the installation discs and double click to install Check your discs for Xcode or Developer Tools Run the installer and install everything other than the documentation For Mac OS X 10 3 you need to install Xcode Tools version 1 2 or later
18. fault workspace Recent projects Recent Files Import project Ej Save tri 5 d Save as Save all Files CEri ShiFE 5 Save project Save project as Save project as user template Save all projects Save Workspace Save workspace as Close workspace R Close file Ctrl Close all Files Ctrl Shift Close project Close all projects ees om include ciostream nt maint std cout lt lt Hello world lt std endl return 0 e and version GNU gdb 6 3 l dgoetz MYD CU l FIRSTP l main cpp 5 ished with status O a wm 11 Insert Read Write 2 When you exit the program you may be asked to save the Workspace and the Layout The Layout refers to the placement of various windows that you may have positioned Generally you would select to Save the Layout unless you know you really do not want it saved The Workspace refers to the projects you are working on It is possible for you to be working on multiple projects within your workspace Saving your workspace will allow you to return to the same set of projects when you next open Code Blocks 35 of 61 To open a project todezBlocks 1 0 e SAVE PROTEGE SVE prEapect AS Sawe praject as user bernnplabe awe all Barajeccs Fose all projects From the File menu select Open Ckrl O Code Blocks M fhe open source cross platform HE 36 of 61 p peer S T Look in E First Program dm Ne obj E First Pr
19. files Multiple selection Select Files to remove From First Pra main cpp sample cpp Wildcard select Toggle selection Select All Deselect All Selected 1 Place a check mark next to any file s that you wish to remove Press OK when you are done 25 of 61 Confirmation X Are vou sure vou want bo remove these Files From the project Yes Mo You will need to confirm that you wish to remove the file s Press Yes if you are sure you want to remove them Otherwise press No First Program CodezBlocks 1 0 File Edit View Search Project Build Debug wxSmith Tools Plugins Settings Help Se amp I RI Ob OE Build target Debug ENS IPS 0I Management E Projects Symbols El Workspace Fag First Program Sources main cpp Sf Code Blocks XA Code Blocks Debug Loading AStvlePlugin 4utosave BYOGames CBProfiler CB Koders Class Wizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger FilesExtensionHandler DeyPakUpdater DragScroll Envvars Source Exporter HelpPluain cbKevBinder ScriptedWizard ToDoList we lt cSmith wxSmithfime wecSmithvvizard Windows PLookNFee EI Running startup script You will now see an updated listing of the Sources in your file You should now see only Main cpp In the Open Files list there may be a file called Untitled Please ignore this 26 of 61 To edit a file from your project do
20. he warnings demanded by strict IS and 150 C pedantic e Warn iF maini is not conformant main Strip all symbols From binary minimizes size 5 Optimize generated code For speed O Optimize more For speed 01 Cinkimize even mare For coeed n0 1 E When this is done the Project Build options window will come up Make sure that the Produce debugging symbols g is checked Press OK when done 29 of 61 main cpp First Program CodezBlocks 1 0 E File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help 1E Bl amp gt E Qe ud Ckri Fa jJ 3 Compile current File Ctrl ShiFk F9 mainQ int L Ip Run Chrl F10 irano in 9 gt e m e Build targe t5 Build and run F3 DE Se PO ie z z Rebuild Ctrl F11 Clean dbx Projects Build workspace E Q Workspace Rebuild workspace E First Program Clean workspace Sources E main cpp R Ahort world lt lt std endl Y osuo eir Release Untitled egies 3 Debugger Setting breakpoints Debugger name and version GHU gdb 6 3 At E DOCUME lL qgoetez MYDOCU 1L FLIRBSTP lL fmain cpp 5 Debugger finished with status oO Build target WINDOWS 1252 Line 6 Column 11 Insert Read Write 5 Epor Maketile Build messages After clicking on done the system will return to Main cpp When testing your code make sure that Debug is selected as the target to use This way
21. ile with the cbp extension 38 of 61 Debugging a Program As your programs become more complicated there will be a need to trace the program execution step by step or place break points where you wish the program to pause This is where a debugger is utilized A debugger can pause your program and you can watch the values of the variables that you have defined The following is a sample program that can be traced line by line while watching what happens as each line of code is executed main cpp debug Code Blocks 1 0 File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help J fad 5 amp Vx OD o5 obo 0 Build target Debug JE VITRO mom E PEBIECER ere 1 finclude iozstream ge Workspace using namespace std Flag debug 3 l 1 F9 Sources i int addemiint int on main cpp E Sint addemiint a int b T int c a 3 c athb Lo ll return c Opened Files 14 int naini main cpp 16 int x 5 y z l8 z addemix wyi 193 cout lt z lt 4 endl el return 0 s i E Document WINDOWS 1252 Line 16 Calumn 21 Insert Read Write 5 39 of 61 First it is necessary to set a place in the code to have the program pause This is done by using the Debug pull down menu and clicking on Run to Cursor The cursor should be over the first line of code where you wish to start the tracing process This starts the debugging process
22. licht projec SDL Smartwir QT4 project SDL project Smartin project Vjew as Pd Large icons List are rmi Eb wi dtidaske of Why are some Wizards marked in red 13 of 61 Console application Press Next to go to the next step 14 of 61 Console application P o X Please select the Folder where vau want Ehe new project l al Co nso le to be created as well as its title Project title First Program Folder to create project in Project Filename First Program Resulting Filename invalid path z Back Meck gt Cancel Start by filling in the Project Title You will notice that the Project Filename automatically becomes the same name If you wish you can change the filename but for simplicity leave it as is To specify the location of the folder to contain the project click on the button selected in the picture above and browse to a folder on your drive to store the project Generally you can save it in My Documents Press Ok after selecting My Documents 15 of 61 Please select the compiler to use and which configurations vau Wank enabled in your project v Create Debug configuration Debug Debug options Output dir binibebug Objects output dir obiibebug v Create Release configuration Release Release options Output dir biniRelease Objects output dir obiRelease z Back Cancel When the directo
23. ll Envvars Source Exporter HelpPluain cbKevBinder ScriptedWizard ToDoList we lt cSmith wxSmithfime weecSmithvvizard Windows PLookNFee E Running startup script Wwelcometo Erle The system will then return to the First Program window and you are ready to write your program It should be noted that the Build target is Debug which will allow you to use the debugger to find errors In the Management area of the screen Shift F2 toggles the Management display you will see the files that are part of the project in the Projects tab To see the source files click on the plus s to expand the Workspace and its subdirectories 18 of 61 First Program CodezBlocks 1 0 File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help r8 amp E Sos ob e e e Build target Debug BBP mcol1 r Management Workspace g First Program FES Sources main cpp Opened Files ti Code Blocks X Code Blocks Debug Loading AStvlePlugin Aubtasave BYOGames CBPrafiler CB Koders Class Wizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger FilesExtensionHandler DeyPakUpdater DragScroll Envvars Source Exporter HelpPluain cbKevBinder ScriptedWizard ToDoList we lt cSmith wecSrithMine weecSmithvvizard Windows PLookNFee in Running startup script Wekmeto 00000000 00000000000 ELLE LLL LLLA Under Sources there 1s a file called main cpp which i
24. mpile current File Clrl S5hift Fa D Run Ctrl F10 9 gt eS m Build arge e Build and run z HE Ne P 3 0 00 Q E nebuld Ctrl F11 ement re Clean Projects q b Build workspace Eg Workspace Rebuild workspace E First Program Clean workspace ae woe R Abort world lt lt std endl Errors Select target main cpp oo F Untitled G Build log Process terminated with status O 0 minutes l8 seconds errors O warnings wn Build messages Build and rur WINDOWS 1252 Line 1 Column 1 Insert Read Write 5 Test the project from the Build Pull down menu by clicking on Build and Run This step will build an executable file for you A project build will take the compiled versions of your source files and combine them into one program You are able to press F9 which is a keyboard shortcut that will build your project and run it at the same time As you gain more experience with the system it will be easier to just press F9 to Build amp Run your program The Message window will indicate if there are any errors during a compile or build phase 32 of 61 m worldt any key to continue This is the output from my first program Notice that besides displaying Hello world it also says to Press any key to continue with the program paused Pressing any key will exit the program If you execute the program by going to a console window you will not see
25. ogram cbp px FE vu Documents My Computer File name Open hiy Network F Cancel Files of type ade Blocks project Files From the Files of type in the window select Code Blocks project files and then select the cbp file pertaining to your program Press Open when done 37 of 61 main cpp First Program Code Blocks 1 0 File Edit View Search Project Build Debug wxSmith Tools Plugins Settings Help SRolt I kobla Oo bP GE Build target Debug BE pT mU mi Projects ge Workspace c5 First Program H F9 Sources finclude iostream int mairi 1 std cout Hello world std endl return 0 oO J m n Ww he E Opened Files main cpp Build log Build messages 3 Debugger t E DOCUHE l cdqosetz MYDOCU l debug main cpp 3 Continuing t E DOCUIHE l qgoetz MYD CcU l debucdg mnmain cpp 19 Continuing Program exited normally Debugger finished with status oO wn E Document WINDOWS 1252 Line 6 Column 11 Insert Read Write Z The project has reopened You can get more space to see your program if you close the Messages window Pressing F2 toggles the display of the messages The Messages window has been turned off for the remainder of this tutorial to allow more space to be visible on the screen Note You may also open a project directly from Windows Explorer by double clicking on the f
26. on Alt EC Workspace 2 T Step into shift F7 3 Mig debug a 48 Step out CirI Shift Er I e Sources JE main cpp E Toggle breakpoint 7 m Run to cursor F4 B A _____ Y Y ylS Y _ _________4____ 8 Add symbol File 10 Debugging windows k Information d is Edit watches 7 pened Files l4 Attach to process E main cpp 15 Petach Send user cammand ta debugger 159 cout lt z lt lt endl ME return 4 Toggle break WINDOWS 1252 Line 9 Column 3 Insert Read Write 5 You can further define places in your program to pause and allow you to inspect the code This is done by setting breakpoints in your code You can have zero or more breakpoints in your code When the debugger encounters a breakpoint the program pauses and the debugger will allow you to inspect your code The breakpoint remains until you remove it It can be Toggled with F5 51 of 61 main cpp debug Code Blocks 1 0 File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help PSR SlA v X 9 e a s addemtint a int b int o b 3 es e Build target Debug AE uz x a on gas e mi Projects jd b 1 finclude iozstream ge Workspace using namespace std ig debug 3 l FS Sources int addemiint int bue L main cpp E Sint addemiint a int b int c E 3 c ath l 11 return c 14 int main 16 int x 5 yee E l
27. r addemtnt a int b int ob9 90 Build target Debug 4E Me TT mau 63 m Projects jd b 1 finclude iozstream ge Workspace using namespace std Flag debug 3 l O Sources int addemiint int m main cpp E Sint addemiint a int b T int c a8 3 gt c ath Lo ll return c Opened Files 14 int naini A main cpp 16 int x 5 y 4 E 18 z addemix yi TS cout lt z lt 4 endl el return 0 4 E Document WINDOWS 1252 Line 9 column 1 Insert Read Write 5 When the program pauses at the break point a red circle with a yellow triangle mark will appear at the breakpoint 54 of 61 L main cpp debug Code Blocks 1 0 n Stop debugger at Ge En E Mex line F dex hSstruchion AlE F 7 ge Workspace EE debug Ef Sources Step out me iN Toggle breakpoint FS El Sda symia hiie Detach sena User command bor gebugger eem cout lt z lt lt endl ee meenten CE ata return 0 ee m u Eoaea ee uum um pue ea TENE EET UEM E E UTE EE g EEEE EEEE EEEE EE EEEE EENETI You can set multiple breakpoints The keyboard shortcut F5 allows you to toggle the breakpoint at any line 55 of 61 main cpp debug Code Blocks 1 0 File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help SR ol AE SCENES c bb amp se Build target Debug JE Ne TP S DT 63
28. ry for your project has been selected the system will return to the Console application As shown Code Blocks will create a directory called First Program Project Title and returns your selected directory in Folder to create project in Inside that directory will be the Project filename First Program and a resulting filename which contains a Code Block Project file cbp named First Program cbp The project title and project filename in this case are the same However they need not be the same and these names can be altered Click on the Next Button when done The next window to pop up will be the Compiler screen This specifies where the Debug and Release compiled versions of your program will be placed Leave this setting alone and press Next 16 of 61 Console application I3 Console The next window allows you to choose the language that you will use Select the language as C then press Finish 17 of 61 First Program CodezBlocks 1 0 Fie Edit View Search Project Build Debug wx mith Tools Plugins Settings Help Smelt vix 9 e xj 0 b G amp S muidtage pbuns l HE WER mF 1i Management E Projects Symbols Workspace g First Program Sources Opened Files E i f Code Blocks YA Code Blocks Debug Loading AStvlePlugin Autosave BYOGames CBProfiler CB Koders Class Wizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger FilesExtensionHandler DeyPakUpdater DragScro
29. s automatically created for you when you build a console application 19 of 61 Adding Files To Your Project If you have a project with additional existing files go to the Project menu and select Add files This will bring in the files associated with your program You also have the option to Remove files performing Build options and to Set programs arguments First Program Code Blocks 1 0 File Edit View Search i eae t HET OP SOO i05 el Tc a A Management Projects Symbols Wor k space 3 g First Program HE Sources Opened Files Project Build Debug wx5mith Tools Plugins Settings Help Add Files Add Files recursively Remove Files Project tree Set programs arguments Build options Properties Code Blocks Loading AStvlePlugin Autosave BYOGames CBProfiler CB Koders Class Wizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger FilesExtensionHandler DeyPakUpdater DragScroll Envvars Source Exporter HelpPluain cbKevBinder ScriptedWizard ToDoList we lt cSmith wxSmithfime weecSmithvvizard Windows PLookNFee ie Running startup script ddflesto fl 20 of 61 Add files to project Look in y First Program de t First Program chp ef E C main cpp 1 VES m hy Computer File name Open Files of type All files Cancel Clicking on Add files to project will
30. space unindents Use Advanced RegEx searches Show indentation guides Show line numbers EEEE EA No mM v Highlight line under caret eT Home key always moves caret to fir Highlight occurrences Editor title is Ehe File s C3 name only no path information relative Filename to the project File 8 of 61 c Select the Margins and Caret tab on the right of the window i Choose Visible line from the Right margin hint i Set the Hint Column to 72 Your screen should now look like the figure Configure editor Margins and caret Folding GR meee tre Ale CLEN PIT Margins and caret Left margin width For line numbers fin chars Dynamic setting Addjremove breakpoints by lefE clicking Right margin Right margin hint Visible line hd Hint column Taret Width Colour Period fin milliseconds X Jem 9 of 61 d Choose the Source formatter Caret tab on the right of the window i Select K amp R from the style menu Note Your instructor may use a different style if so examine each style and choose the style that matches your instructor s preferred indentation Your screen should now look like the figure Configure editor Source formatter Style Indentation Formatting Styles Sample CO ANSI namespace foospace OKER int Foot ED aur if iis Bar hart GNU return 1 Java else return 0 Keyboard shortc
31. step so that it becomes clear where the problem is and why your program does not execute properly This is called debugging the program Hand tracing is useful in helping beginners understand where the bugs are and correct the program appropriately Automatic tools have also been developed to help you trace programs that you have written and will be an important tool as your programs become more complex This type of tool is called a debugger A debugger lets you pause a program while it is in the middle of running and watch what is going on Some debuggers work as command line line debuggers but newer debuggers have a nice graphical user interface which is useful in helping you watch variables that you have defined as the program executes The graphically based debugger environment is part of what 1s called the Integrated Development Environment IDE The purpose of these notes is to introduce you to this environment and help you learn how to use it as you develop and hone your programming skills A debugger cannot solve your problems for you It is merely a tool to assist you when programming You should first attempt to read over your code and using paper and pencil analyze the code to get an understanding of what is going on Once you have gotten an idea of where in your code you have an error you can then set the debugger to watch certain variables in your program Watching your code will show you step by step how your program is being executed
32. t Debi ME continue addemfink a int b int s Solo 2 anagement main cp 42 Next line F7 d PX Projects q b 1 Next instruction Alt F EH Workspace P Step into Shift F E debug n Step nut CEri ShifE F7 Ee Sources BEL main cpp E Toggle breakpoint F5 7 Eg Run to cursor F4 peri e 8 Add symbol File 10 Debugging windows d 11 Information lz Edit watches ened Files p RE Attach bo Process main cpp 15 l5 Detach Send user command to debugger 19 cout lt z zc endl el return 0 Continue exe WINDOWS 1252 Line 11 Calumn 1 Insert Read Write Z When you are done debugging you can click on Continue and your program will run to completion This is better than selecting to Stop debugger The reason it is better to Continue is because the program comes to a natural end rather than aborting However if your program is stuck in a loop or you are sure you can exit safely you can select from the Debug menu Stop Debugger 50 of 61 main cpp debug Code Blocks 1 0 File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help 1E Bl S amp E DD LIE tat F8 Bp NET R Stop debugger addemifint a int b int obe m e ous target i P S z bud target by LIS continue cory m 00 LM main cE Ts Hest line re q1 X Projects 3 d L 4 Next instructi
33. tistics Compiler copystrings Debugger FilesExtensionHandler DeyPakUpdater DragScroll Envvars Source Exporter HelpPluain cbKevBinder Scripted Wizard ToDoList we lt cSmith wxSmithfime weecSmithwizard Windows PLookNFee E Running startup script E Document default Line 1 Column 1 Insert Read Write 5 The Sources now has sample cpp as a source file in addition to the main cpp file Since the sample cpp is not needed for your project please remove it 24 of 6l sample cpp First Program CodeBlocks 1 0 D File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help ee ole SSS OP OE OIe F Projects Symbols El Workspace Fag First Program FES Sources _ main cpp LETETT L sample cpp 7 Opened Files Ej Untitled Add Files Add Files recursively Remove Files Project tree d Set programs arguments Build options Properties fi Code Blocks X Code Blocks Debug Loading AStvlePlugin Aubtasave BYOGames CBProfiler CB Koders Class Wizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger FilesExtensionHandler DeyPakUpdater DragScroll Envvars Source Exporter HelpPluain cbKevBinder ScriptedWizard ToDoList wx Smith wxSmithfime weeSmithwizard Windows PLookNFee _ Running startup script Remove Files default Line 1 Calumn 1 Insert Read Write 5 From the Project menu select Remove
34. ts description Mullsart Install System v2 35 z Back Cancel Take the default settings by pressing Next 6 of 61 LI CodeBlocks Setup Choose Install Location Choose Ehe Folder in which bo install CodeBlocks Li Pragram Files CodeBlacks dur ect Install System veu Take the default folder to install CodeBlocks to and then select Install 7 of 61 Step 3 Customization of the Code Blocks User Interface Optional The following steps will enable you to customize your IDE so that it is will be consistent with what your instructor will be using in class 1 Configure the editor a Choose Editor from the Settings Menu b Under the General Setting tab i Change the font size to 10 or 12 point Use the Choose button ii Under Other Options place a check mark the following options e Show line numbers e highlight line under caret e highlight occurrences Your screen should now look like the figure Configure editor General settin Font This is sample text Default encoding when opening files WINDOWS 1255 TAB options End af line options Use TAB character Show end af line chars TAB indents Strip trailing blanks TAB size in spaces 4 End files with blank line l Ensure consistent EOLs End af line mode CR LIF Folding Indent options Other options Auto indent ward wrap Smart indent Use POSIX style For RegEx searches Back
35. uble click on it s name from Sources and it will appear in the window with line numbers You can now edit the file and prepare your program main cpp First Program CodezBlocks 1 0 File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help SERol AE So ES 0 b GS muidtage pbuns l bck RUE Trid DN i Projects E Q Workspace E a First Program B Sources main cpp include lt iostream gt int maini E std cout Hello world std endl return 0 EO TJ m mq Hx CO DX FP Open Files list fi Code Blocks x Code Blocks Debug Search results 4 d Loading AStvlePlugin Autosave BYOGames CBProfiler CB Koders Classwizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger FilesExtensionHandler DeyPakUpdater DragScrall EnvVars Source Exporter HelpPlugin cbKevBinder Scripted Wizard ToDoList weeSmith wecSmithMime wecomith Wizard WindowsxPLookMFee ni 1m mpg b k m rime E Document WINDOWS 1252 Line 1 Calumn 1 Insert Read Write 27 of 61 main cpp First Program CodeBlocks v1 0 B mi x File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help oe res P e Add Files recursively Bo Remove Files gt ODSTO Project tree b LE Me oy T Ne m 7 Set programs arguments Build options Projects Properties E Q Workspace a First Program B So
36. urces s 1 main cpp int mairi i E 1 std cout Hello world std endl return 0 oO J m m gH CO M Opened Files xd main cpp s oo 1 Untitled fi Code Blocks XN Code Blocks Debug 4 Search results Loading AStvlePlugin Autasave BYOGames CBProfiler CB Koders ClassWizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger FilesExtensionHandler DeyPakUpdater DragScrall EnvVars Source Exporter HelpPlugin cbKevBinder ScriptedWizard ToDoList wreeSmith wx5mithMime wecomith Wizard WindewsxPLoakMFeel n 1m mpg b k m rime Set the prajr WINDOWS 1252 Line 1 Calumn 1 Insert Read Write In order to check that Debug is running you can use the Project pull down menu and click on Build Options 28 of 61 Project build options E a x First Pragram Selected compiler J fenu GCC Compiler Compiler Linker Directories Commands Custom variables Make commands Policy Append target options to project options Compiler Flags other options defines Categories lt All categories gt i Ml Produce debugging symbols q Profile code when executed pg Enable all compiler warnings overrides every other setting vall Enable standard compiler warnings 4 Stop compiling after First error WwFatal errars Inhibit all warning messages w Enable warnings demanded by strict 150 C and ISO C pedantic Treat as errors E
37. uts Custom weeSmikh settings Preview e Choose OK in order to save your customizations 10 of 61 2 Configure the Help files a Download the C help file from http onnerby se daniel chm cppreference com cpp chm b Save the cpp htm file to your c Program Files Codeblocks directory c After saving the file right click on the file choose Properties and unblock the file so that it will be accessible to the Code Blocks IDE d Choose Environment from the Settings Menu e On the tab to the left of the window scroll down to the Help Files section Choose Add and enter C Help g Use the file browser button LJ to locate the file you have just saved It should be at C Program Files CodeBlocks cpp chm h Place a check mark in the this is the default help file Shortcut F1 Your screen should now look like the figure Environment settings HeaderFixup configuration C Program FilesiCodeBlacksycpp chm TIP ikevword will be replaced by the word under the cursar This is the default help File shortcut F1 This line represents a Full command to be executed Open this File with the embedded help viewer only For HTML Files Preserve keyword case To do list Default keyword value E i Choose OK in order to save your customizations By pressing F1 you will now be able to obtain help on the word under your cursor 11 of 61 First Project After
38. ve all files Ckrl 5hift 5 Cod Blocks Save project Save project as The open source cross platform IDE Save project as User bemplate Save all projects Sweets le Blocks x Code Blocks Debug Save workspace as StylePlugin Qutosave BYOGames CBProfiler CB Koders d CodeCompletion CodeSnippets CodeStatistics Compiler diese biel ciple s Debugger FilesExtensionHandler DeyPakUpdater DragScroll o Aer e ource Exporter HelpPlugin cbKevBinder ScriptedWizard peas i xS mith wxSmithMime wx Smikh wieard WwindawsxPLoakMFeel Close all Files i Erl S5hifE W arkup script Close project lose all projects E 12 of 61 This will bring up the New from template window Opening clicking on Console Application will then allow you to write a program on the console The other application are for developing more advanced types of applications After selecting Console application click on the Go button to begin using the Console Application Wizard New from template Projects Build targets Code Blocks plugin Empty project FLTK project g ce Ogre project OpenGL project un a lin rol IT n Zk abir libe sews 4 1 Select a wizard type First on the left 2 Select a specific wizard From Ehe main window Filter by categories if needed 3 Press Go Category lt All categories gt D application Direct Dynamic Lint application Library GLEW LUT Qoo zu GLF project GLUT project Irr
39. you have finished downloading and setting up the Code Blocks system you can be in to write code Code Blocks creates what is called a Workspace to keep track of the project you are working on It is possible for you to be working on multiple projects within your workspace A project is a collection of one or more source as well as header files Source files are the files that contain the source code for your program If you are developing a C program you are writing C source code cpp files Header files are used when you are creating library files h files A library is a collection of functions that are called to perform specific tasks such as doing math etc Setting up a project allows you to keep track of all the files in an organized way When first starting out in computer programming generally your projects will consist of a single source file However as you gain experience and work on more complex projects you will have projects containing many source files and dealing with header files as well To create a project click on the File pull down menu open New and then Project Start here Code Blocks 1 0 E B x File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help Mew Empt File CEri ShiFE M 34 Open ctrl 0 Project Open default workspace Build target Recent projects File Recent Files Ry custom TTT From user template impias praece z el Ej Gave ctri 5 wv Save as Sa
40. z has not been assigned it s value on line 18 yet The current value is a random value 43 of 61 zj Code Blocks 1 0 h Project Build Debug weSmith Tools Plugins Settings Help hes ES 3cal variables x 5 9 ESI M maint int Debug Wie TRO oO main cpp 4 bx Jnckion Arguments ne Ma arguments l finclude ziostream using namespace std Bj 4 int addem int inti 5 amp lint addemiint a int hb Y inb c a EI c ath 10 ll return c Le 13 Opened Files l4 int main main cpp 15 ii 16 int x 5 y 2z z 17 i8 gt z addemix y ILS cout zz 2 endl 0 el return zz eS ni E pocument WINDOWS 1252 Line 18 Calumn 1 Insert Read Write 5 Line 18 has a yellow marker on the left side This indicates that the program has paused on that line which is the breakpoint 44 of 6l main cpp debug Code Blocks 1 0 File Edit View Search Project Build Debug weSmith Tools Plugins Settings Help m EE amp E I EE t Fg LER ERE 3 Stop debugger aint int c bP So E target O P SO tu tretie b E Continue cur 5 ToC E a aii ii ie main CE T Next line Fi T dex Projects i 4 Next instruction Alt F E Q Workspace 7 P Step into Shift F7 rj 3 Eig debug 4 f Step out Ctrl Shift F7 E B Sources E main cpp z Toggle breakpoint F5 7 Erg Run to cursor F4 B JJJJJJJPJ J

Download Pdf Manuals

image

Related Search

Related Contents

Samsung MD46B  KSC-SW1 - Kenwood  PARTNER Small Office Edition Quick Setup Guide  Sony Cyber-shot Marine Pack MPK-WB User's Manual  

Copyright © All rights reserved.
Failed to retrieve file