Home

Code::Blocks Student Manual - Computer and Information Science

image

Contents

1. From the File menu select Open 38 of 64 Open file Look in ja First Program amp er E3 4 History DE Desktop ON F My Documents 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 39 of 64 main cpp First Prarain CES Ele Edit View Search Project Build Debug wxSmith Tools Plugins Settings Help Seol t Vie Palas O D DDE puldtarcetreng AEETI MPO zd T main cpp Projects 4 gt aQ workspace EL First Program H P Sources finclude lt iostream gt int maini Et std cout lt lt Hello world lt lt std endl return 0 1 2 E 4 5 6 8 5 Opened Files 4c E DOCUME l goetz MYDOCU 1 debug main cpp 9 Continuing At E DOCUME 1 goetz MYDOCU 1 debug main cpp 19 Continuing Program exited normally Debugger finished with status 0 M E iDocument WINDOWS 1252 Line 6 Column 11 Insert Readjwrite 7 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 file with the cbp extension 40 of 64 Debugging a Program As
2. Next line i Next instruction Ag Workspace E M debug Sources main cpp Gr Shift y cout z lt lt endl return 0 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 55 of 64 addem int a int b int Y Li B ae t finclude lt iostream gt ps using namespace std int addem int int int addem int a int b int c c atb return c i naini int x 5 y 2 z z addemix y cout lt z lt lt endl return 0 When the program pauses at the break point a red circle with a yellow triangle mark will appear at the breakpoint 56 of 64 y9 Stop debugger Contre Next line 3 Next instruction Ag Workspace Step ir EL debug Sources main cpp Detach cout z lt lt endl return 0 You can set multiple breakpoints The keyboard shortcut F5 allows you to toggle the breakpoint at any line 57 of 64 main cpp d finclude lt iostream gt int addem int int int addem int a int b int c c atb return c main i int x 5 y 2 z z addemix y cout z lt lt endl return 0 This screen shows breakpoints on lines 9 and 19 but line 9 indicates that the code has executed to that point 58 of 64 main cpp
3. cout lt lt Hello world lt lt std endl return 0 B Open Files list Opened Files E co 1 Untitled2 adn eer rey Autosave BYOGames CBProfiler CB Koders ClassWizard odeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger 29 of 64 Build op AQ Workspace B n First Program E B a 35 std cout lt lt Hello world lt lt std endl ae return 0 Lodo WD enm BYOGames CBProfier CB Koders ClassWizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger ilesExtensionHandler DevPakUpdater DragScroll EnvVars Source Exporter Smith Wizard WindowsxPLookNFeel imei mk wks re covink In order to check that Debug is running you can use the Project pull down menu and click on Build Options 30 of 64 Project build options ini x Selected compiler Janu 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 lt bi Produce debugging symbols 3 Profile code when executed pa Enable all compiler warnings overrides every other setting Wall Enable standard compiler warnings wW Stop compiling after First error WfFatal errors Inhibit all warning messages w Enable warnings demanded by strict ISO C and ISO C pedantic Treat as errors the w
4. 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 25 of 64 sample cpp First Program Cod Ei i main cpp ie sample 5 cpp 3 Opened Loading AStylePlugin Autosave BYOGames CBProfiler CB Koders ClassWizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger FilesExtensionHandler DevPakUpdater DragScroll EnvVars Source Exporter HelpPlugin cbKeyBinder ScriptedWizard ToDoList wxSmith wxSmithMime wxSmithwizard WindowsxPLookNFeel Running startup script 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 26 of 64 sample cpp First Program Code Blocks 1 0 File Edt view Search Project Build Debug wxSmith Tools Plugins PImHGOGI Ob ORG Projects Symbols AQ Workspace EL First Program E F Sources main cpp sample cpp Code Blocks Debug Loading AStylePlugin Autosave BYOGames CBProfiler CB_Koders ClassWizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger FilesExtensionHandler DevPakUpdater DragScroll EnvVars Source Exporter HelpPlugin cbKeyBinder ScriptedWizard ToDoList wxSmith wxSmithMime wxSmith Wizard WindowsxPLookNFeel Runnin
5. 4 F Stepout Cert Shift T F uns 5 main cpp g Toggle breakpoint F5 7 ME Runto cursor F4 8 9 Add symbol File 10 Debugging windows Breakpoints 1 Information Call stack pt ist js Edi watches CPU Registers 73 Opened Files 14 TNT REM Disassembly 15 Detach Examine memory 16 Running threads 17 Send user command to debugger cout z lt lt endl return 0 4 b watch variab WINDOWS 1252 line 18 Column 1 Insert Read Write a 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 44 of 64 Watches ae eo xX 5 i ycl2 i 2 1 El Function Arguments oo No arguments These are the watches that the debugger is displaying Notice that x amp y have the correct values Variable z has not been assigned it s value on line 18 yet The current value is a random value 45 of 64 inction Arguments No arguments 3 Opened Files aint addem int int int addem int a int b int c c atb return c main int x 5 y 2 z z addem x y cout lt lt z lt lt endl return 0 Line 18 has a yellow marker on the left side This indicates that th
6. 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 64 Table of Contents Introd ne HOT sapete e eti elem atten Ghats ares hci che Ar eS E en cease aed lad a cha als 3 Installationof Code Bloeks easi d ate Qe vate ioter lesu ende UND Uo iene ha PAN eit ada DERE ive eee 4 Step E Dosynload the SOIBWALG ceci ee eadeni da vedkepe tee RSEN UHR LO eR Eea Ta aia CUN OQ Een epu IN ERU dnd 4 Step 2 Install the SOL Wale eere os e etes ore ute to Rest e sn pu ue dg teo T a a r o eM us 5 Step 3 Customization of the Code Blocks User Interface Optional ssesesssss 8 virium T 13 Adding biles To Your Projecte sen e Rode E Que a deat a een cT edes ibo coil Es ee rice 22 Deb esinb a Programserien rae eoe eR DR ON date du eap MM LL LE Ld ere 4 If you are using the Mac OS you will need to do the following eeeeeee 62 Pr c Install SlepBiss cce cours denies Maecen ode bd pleut cua e beso oni te equipe es eed a EER NEEE a bert reor edes 62 Appendix A Installing Code Blocks under Mac OS X and Linux ssssssssssseeeeeeeeenens 62 Installation for Fedora 5 LAnuxocdee o o o Sects sone oU er diii d udiedite ME ii uae Ee 63 Installation for Db ntir EX eie Coo t
7. Next line E 4 bx Profetts 1 9 Next instruction AlCET EQ Workspace Z By step into Shift F7 my debug i Step out Grl shiFE E B 3 Sources E is E main cpp 6 Toggle breakpoint FS 7 ME Run to cursor F4 Pus 3a cU mmi iM 3 Add symbol file 10 Debugging windows gt i Information gt 13 Edit watches Opened Files main cpp Attach to process Detach Send user command to debugger 19 cout lt z lt lt endl zl return 0 4 b Toggle break WINDOWS 1252 Line 9 Column 9 Insert Read Write a 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 53 of 64 addem int a int b int p 5269 1 1 a include lt iostream gt using namespace std nt addem int int nt addem int a int b int c c atb return c main int x 5 y 2 z z addemix y cout z lt lt endl return 0 A breakpoint has been set at line 9 The red circle indicates that there is a breakpoint in the code 54 of 64 X 10H OEE GRET iddem nt a int b int ss n if ER 1 Continue nifi Ww En fy
8. PakUpdater DragScroll EnvVars Source Exporter HelpPlugin cbKeyBinder ScriptedWizard ToDoList wxSmith wxSmithMime wxSmithwizard WindowsxPLookNFeel Running startup script 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 20 of 64 First Program Code Blocks 1 0 First Program E P Sources main cpp 3 Opened Files Loading AStylePlugin Autosave BYOGames CBProfiler CB_Koders Class Wizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger FilesExtensionHandler DevPakUpdater DragScroll EnvVars Source Exporter HelpPlugin cbKeyBinder ScriptedWizard ToDoList wxSmith wxSmithMime wxSmithwizard WindowsxPLookNFeel Running startup script Under Sources there is a file called main cpp which is automatically created for you when you build a console application 21 of 64 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 per
9. The graphically based debugger environment is part of what is 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 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 64 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 i
10. Under Other Options place a check mark the following options Show line numbers highlight line under caret e highlight occurrences Your screen should now look like the figure 8 of 64 Configure editor General settings Font This is sample text Default encoding when opening files WINDOWS 1255 General settings TAB options End of line options Use TAB character C Show end of line chars TAB indents v Strip trailing blanks TAB size inspaces 4 End files with blank line C Ensure consistent EOLs End of line mode CRLF w Folding Indent options Other options Auto indent word wrap v Smart indent Cluse POSIX style for RegEx searches v Backspace unindents Use Advanced RegEx searches Cl Show indentation guides Show line numbers Show spaces No v Highlight line under caret X ERR Home key always moves caret to Fir Margins and caret Highlight occurrences FOITETITTINT ITI Editor title is the file s O name only no path information S relative filename to the project file C Select the Margins and Caret tab on the right of the window i Choose Visible line from the Right margin hint il Set the Hint Column to 72 Your screen should now look like the figure 9 of 64 Configure editor M arg Left margi ins and caret E NEST General settings 10 of 64 Choose the Source formatter Caret tab on the righ
11. a B main cpp Ctrl F7 main c T Next line F 1 Y Next instruction Alt F7 s 5 Step into Shift F7 4 4 Step out Ctrl Shift F7 5 6 FS 7 8 3 Add symbol File 10 Debugging windows gt e Information gt 13 Edit watches i Attach to process 16 Detach Send user command to debugger cout 4 z lt lt endl return 0 ES 4 b J Run program WINDOWS 1252 Line 18 Column 18 Insert Read Write a The next step in debugging a program is 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 is called a Breakpoint Now you can instruct the debugger to run the program up to the cursor s position line number 42 of 64 Documents and Settings goetzMy Documents debug debug exe The program will generate a blank window It is blank since that program has yet to execute any line that displays something 43 of 64 main cpp debug Code Blocks 1 0 File Edit View Search Project Build Debug wxSmith Tools Plugins Settings Help Janaki Yd Hub F TUUS Q Stop debugger aint int a D FS puid target Deb JE continue em i MPO Te main c T Next line FF 4 bx Projects 1 Next instruction Alt F7 El Q Workspace Step into Shift F i Mg debug out Ctrl Shift F7 B B Sources
12. arnings demanded by strict ISO C and ISO C pedantic e Warn if main is not conformant Wmain Strip all symbols From binary minimizes size s Optimize generated code For speed O Optimize more For speed O1 nFimize even mnre For need F 021 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 31 of 64 main cpp First Program Code Blocks v1 0 File Edit View Search Project Build Debug wxSmith Tools Plugins Settings Help lol xl PIB t 4on Msn i P Q SG nite e aia and run rn F Rebuild Ctrl F11 n Gem BETR Oh O T j 4 Build workspace HB Q Workspace Rebuild workspace First Program Clean workspace B P Sources world lt lt std endl ATEM Release Files a main cpp 1j Untitled2 Build log Build messages Debugger Setting breakpoints Debugger name and version GNU gdb 6 3 At E DOCUME 1 goetz MYDOCU 1 FIRSTP 1 main cpp 5 Debugger finished with status 0 Build target WINDOWS 1252 Line 6 Column 11 Insert Re ad Write di 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 when you Compile your program you will have a Debug version available To compile a file mea
13. atus 0 36 of 64 Now you can select to save the project main cpp First Program Code Blocks v1 0 File Edit view Search Project Build Debug wxSmith Tools Plugins Settings Help New rh By 4 Open Ctrl O Y main int Recent projects id Recent files gt Import project gt include lt iostream gt id Save Girl 5 a Save as nt maini Save all Files Ctrl Shift S std cout lt lt Hello world lt std endl return 0 Save project Save project as Save project as user template Save all projects Save workspace gE Save isin ae n messages Debugger Close workspace points fe and version GNU gdb 6 3 Q Close File Ctl W l goetz MYDOCU 1 FIBRSTP l main cpp 5 Clase all files CHbShit Ww fished with status 0 z Close project 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 37 of 64 To open a project a Code Blocks 1 0 Ve project project assis e project as user template all pr
14. ce 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 File m 6 9 EA omues n Aree New J Empty file Ctrl 5hift N B 4 Open Ctrl O Project E Open default workspace Build target 9 Recent projects y File Jg Recent files y Custom iem From user template m E Mane Import project b 4 Pri Save Gt S 4 c4 Save as Og Save all files Gtrl Shift s 4 Save proed Code Blocks SAVE project as Tha anen caurce cracenfattarcen INF M Save project as user template ean Save all projects cks Search results Build log Build messages 4 gt A Workspace as A Clase workspace FB Saye everything amp lt Smft 5 Fi Close file tr Glase all files Gtr ShiFE Ww Lo Clase project f pi KE oe default 13 of 64 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 I xj Projects Category zal categories gt a Build targets Files Custom User templa
15. debug Code Blocks 1 0 j Continue couk lt lt z endl return 0 Selecting Continue from the Debugger menu will run the program till the next breakpoint 59 of 64 nt addem int int int addem int a int int c c atb return c maini int x 5 y 2 z z addemix v cout lt lt z lt lt endl return 0 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 60 of 64 When you exit Code Blocks you may be presented with the following window I x P Workspace Default workspace is modified Do you want to save it No eae 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 61 of 64 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 l 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 ins
16. e program has paused on that line which is the breakpoint 46 of 64 Shift F7 Attach to Process cout z lt lt endl return 0 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 47 of 64 i aes finclude lt iostream gt aQ workspace 2 using namespace std Mj debug 3 E Sources je c main cpp 6 int addem int a int b int c nt addem int int c atb return c 73 Opened Files NES naini int x 5 y 2 z z addemix y cout z lt lt endl return 0 The next step is line 9 48 of 64 watches __ Local variables c 16384 EF sanction Arguments poga 5 io b 2 The arguments a and b are shown in the Watches window Notice that the local variable c which has not been set yet has a random value 49 of 64 xddem nt a int b int 7 9 Z i gt Bo T IURE asg debug urces Attach to Process Detach cout lt lt z lt lt endl return 0 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 50 of 64 El Local variables Leu El Function Arguments a 5 ib 2 The debug window reflects the change of c 51 of 64 a7
17. ecute the following command yum install codeblocks 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 8208 msg61085 html msg61085 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 lgp203 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 lines on the terminal sudo apt get update sudo apt get upgrade 63 of 64 3 Install Code Blocks Enter the following line in the terminal sudo apt get install libcodeblocks0 codeblocks libwxsmithlibO0 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 Pro
18. een trs e o i aa petit dad ei ARR EM Ee T 63 2 of 64 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 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
19. es 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 34 of 64 Press 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 the Press any key to continue message E Documents and Settings goetz My Documents First Program first program Hello world E Documents and Settings goetz My Documents First Program Notice that there are double quotes around the file name This is because there is a space in the name If 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 35 of 64 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 1 0 std cout lt lt Hello world lt lt std endl return 0 e and version GNU gdb 6 3 l qoetz MYDOCU l FIRSTP l main cpp 5 ished with st
20. forming Build options and to Set programs arguments Add files Remove files Project tree Set programs arguments Build options H P Sources lb Opened Fes jj Code Blocks XY Code Blocks Debug Loading AStylePlugin Autosave BYOGames CBProfiler CB_Koders Class Wizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger FilesExtensionHandler DevPakUpdater DragScroll EnvVars Source Exporter HelpPlugin cbKeyBinder ScriptedWizard ToDoList wxSmith wxSmithMime wxSmithWizard WindowsxPLookNFeel Running startup script 22 of 64 Add files to project Lookin Fit Poom i O e amp tck ER My Documents 5 TS My Computer amp CENE uus zl My Network P T Files of type Al fes 3 y Cancel VA Clicking on Add files to project will 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 File New Empty file 23 of 64 3 Open Ctrl Open default workspace Recent projects Recent files Import project i Save Coles d save 8S Save all Files Gtri Shift s Save project Save project as Save project as user template Save all projects EPEA z XX Code Blocks Debug Save workspace as StylePlugin Autosave BYOGames CBProf
21. g startup script From the Project menu select Remove files Mutipleselecion Select files to remove from First Program main cpp sample cpp Selected 1 ok cm Place a check mark next to any file s that you wish to remove Press OK when you are done 27 of 64 Confirmation x Are you sure you want to remove these files from the project 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 E Q Workspace Be n First Program Sources main cpp je qned J CodeBlocks XX Code Blocks Debug Loading AStylePlugin Autosave BYOGames CBProfiler CB Koders ClassWizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger FilesExtensionHandler DevPakUpdater DragScroll EnvVars Source Exporter HelpPlugin cbKeyBinder ScriptedWizard ToDoList wxSmith wxSmithMime wxSmithWizard WindowsXPLookNFeel 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 28 of 64 To edit a file from your project double 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 propran finclude lt iostream gt B Q Workspace Br n First Program int main EHES Sources std
22. gramming Languages listing of your programs 64 of 64
23. iler CB_Koders Close SR m d CodeCompletion CodeSnippets CodeStatistics Compiler Pee ered a DIR s Debugger FilesExtensionHandler DevPakUpdater DragScroll Q clase file GEHEN ource Exporter HelpPlugin cbKeyBinder Scriptedwizard xSmith wxSmithMime wxSmithWizard WindowsxPLookNFeel Close all files Gtrl Shift wy i m artup script Close all projects You will be asked if you want to add this file to the project Add file to project x 2 Do you want to add this new file in the active project has to be saved first Choose Yes Code Blocks will ask for a file name to save the file as 24 of 64 ST ax Save in a First Program gt ck E3 My Computer File name sample cpp Save as type C C files Cancel Give a name to the file Pick a name that is related to the content of the file Here it is called sample cpp C files need to be of the type cpp Press Save to save the file Multiple selection JE ini x Select the targets this file should belong to v Debug Wildcard select v Release My Network Re Toggle selection Deselect All Selected 2 7 cm 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
24. maincep debug CodeBlocks vao TES e Edit View Search Project Build Debug wxSmith Tools Plugins Settings Help e SO amp id mese FB Otto OOO Stop debugger addem int a int b int OLOTO cst EDS gt o i i main cr T Next line 4 bx Projects 4 019 Next instruction Ni El Q Workspace Ph Step into Shift F7 Mi debug 4 F Step out CtrI Shift F7 B B Sources s na main cpp g Toggle breakpoint F5 7 ME Runto cursor F4 a l 3 Add symbol File 10 Debugging windows gt ae Information gt Lo mel RN Opened Files 14 Attach Eo process ee A H Sins Bi ee s Detach A Send user command to debugger 19 cout lt lt z lt lt endl 20 21 return 0 22 23 B 4 Continue exe WINDOWS 1252 Line 11 Column 1 Insert Read Write a 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 52 of 64 MALEDA debug Code Blocks v1 0 M s dal x File Edit view Search Project Build Debug wxSmith Tools Plugins Settings Help Ea amp v dE D LB set FB i Yr o Staples hddem int a int b int gt Pozzo OD Qz nud tarcet fden b YE continue ce I me Ol z i x main c 7
25. new project z Ofeli ke B tobe created as well as its title Project title First Program Folder to create project in E Documents and Settings goetz My Documents Project Filename First Program Resulting Filename goetz My Documents First Program First Program cbp lt Back Cancel When the directory 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 18 of 64 i Console application I Console Pride 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 19 of 64 First Program Code TROC v LU T First op rene H P Sources F Opened Files 3 Code Blocks Debug Loading AStylePlugin Autosave BYOGames CBProfiler CB_Koders Class Wizard CodeCompletion CodeSnippets CodeStatistics Compiler copystrings Debugger FilesExtensionHandler Dev
26. ns to take the instructions that you have written and translate it into machine code for the computer to understand 32 of 64 main cpp First Program Code Blocks v1 pace B First Program Sources A z17 t voziai std endl E B Opened Files Les M Untitled2 Debugger name and version GNU gdb 6 3 t E DOCUME l qgoetz MYDOCU l FIRSTP l main cpp 5 Debugger finished with status 0 Compile your file from the Build pull down menu by clicking on Compile current file Ctrl Shift F9 33 of 64 main cpp First Program Code Blocks v1 0 t S amp d O Chr F9 ff Compile current file Ctrl Shift F9 ee Ctrl F10 O D OA O Buid targe e HEB NETT S S Rebuild Ctrl F11 Management n gean Projects 4 Build workspace E Q Workspace Rebuild workspace c First Program Clean workspace E Sources z main cpp Q Abort Errors Select target Export Makefile g a Process terminated with status 0 0 minutes 18 seconds 0 errors 0 warnings Build and rur IWINDOWS 1252 Line 1 Column 1 Insert Read Write a 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 world lt lt std endl p Opened Files main cpp 1i Untitled2 Build messag
27. t 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 64 Step 2 Install the Software Next open click on CodeBlocks install file and the CodeBlocks Setup will begin installing as follows L1 CodeBlocks Setup 1 Iof xj Welcome to the CodeBlocks Setup Wizard This wizard will quide you through the installation of CodeBlocks It is recommended that you close all other applications before starting Setup This will make it possible to update relevant system files without having to reboot your computer Click Next to continue Click Next 5 of 64 m CodeBlocks Setup License Agreement Please review the license terms before installing CodeBlocks Press Page Down to see the rest of the agreement GNU GENERAL PUBLIC LICENSE Version 3 29 June 2007 Copyright C 2007 Free Software Foundation Inc lt http f fsf org 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 xl If
28. t of the window 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 O ANSI namespace foospace OKER int Foot Linux if is Bar bar O GNU return O Java else return Keyboard shortcuts Custom wxSmith settings a Source formatter e Choose OK in order to save your customizations 11 of 64 Configure the Help files h Download the C help file from http onnerby se daniel chm cppreference com cpp chm Save the cpp htm file to your c Program Files Codeblocks directory 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 Choose Environment from the Settings Menu On the tab to the left of the window scroll down to the Help Files section Choose Add and enter C Help Use the file browser button J to locate the file you have just saved It should be at C Program Files CodeBlocks cpp chm 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 Help files class fos b a
29. taller 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 As a test 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 com mand 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 For Mac OS X 10 4 you need to install Xcode Tools version 2 2 or later 62 of 64 For Mac OS X 10 5 you need to install Xcode Tools version 3 1 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 ex
30. tes Code Blocks onsole D application Direck X Dynamic Link plugin acoication application Library a Empty project FLTK project GLFW project GLUT project Irrlicht projec SDL Smartwin g e Ogre project OpenGL QT4 project SDL project Smart win project project a 5 m Sk atic lihr ars Mim 7I IT id rv Midaakc P why are some wizards marked in red 1 Select a wizard type first on the left 2 Select a specific wizard from the main window filter by categories if needed 3 Press Go View as Large icons List 14 of 64 7 i Console application I Console Press Next to go to the next step 15 of 64 Console application I console The next window allows you to choose the language that you will use Select the language as C then press Finish 16 of 64 Console application First Program lc 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 17 of 64 Console application J x Please select the Folder where you want the
31. u ab 3 Ww a dm Thread search cea To do list C Program Files CodeBlocks cpp chm TIP keyword will be replaced by the word under the cursor v This is the default help file shortcut F1 This line represents a Full command to be executed J Open this file with the embedded help viewer only For HTML files Preserve keyword case Default keyword value 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 12 of 64 First Project After 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 sour
32. you accept the terms of the agreement click I Agree to continue You must accept the agreement to install CodeBlocks Nullsoft Install System y2 a5 Back Cancel Select I Agree O CodeBlocks Setup O x Choose Components Choose which Features of CodeBlocks you want to install Check the components you want to install and uncheck the components you don t want to install Click Next to continue Select the type of install Standard Core plugins core tools and core lexers Or select the optional B Default install pag he you wish to E Contrib Plugins i E CB Share Config v MinGW Compiler Suite Description Space required 102 5MB Position your mouse over a component to see its description Nullsoft Install System v2 35 eia cm Take the default settings by pressing Next 6 of 64 O CodeBlocks Setup Choose Install Location Choose the Folder in which to install CodeBlocks Nullsoft Install System v2 35 Take the default folder to install CodeBlocks to and then select Install 7 of 64 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
33. 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 v1 0 r r r Projects finclude lt iostream gt E Q Workspace using namespace std E S debu ue int addem int int LJ eee Gint addem int a int b int c c atb return c 3 Opened Files maini is d main cpp int x 5 y 2 z z addem x y cout z lt lt endl return 0 E iDocument WINDOWS 1252 Line 16 Column 21 Insert Read Write a 4 of 64 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 main cpp debug Code Blocks v1 0 ini xl File Edit View Search Project Build Debug wxSmith Tools Plugins Settings Help mE Vd m Nes F 2 Q Stop debugger O D Q FG buid target Debi LE continue Projects 4 gt El Q Workspace EL debug Sources main cpp Opened Files P

Download Pdf Manuals

image

Related Search

Related Contents

LOREX Technology L15D424321B User's Manual  MORIWAKI SKIDPAD KIT  Model UT750 Digital Indicating Controllers User`s Manual for Loop  Gazette mai 2015 - Lamballe Communauté  SCOTT SDM 60 WH Hugyo  Instrucciones Instruccions Instructions Instructions  Samsung 710NT manual de utilizador  Snapper SG 5000 User's Manual  Manual  DCDtF107  

Copyright © All rights reserved.
Failed to retrieve file