code::block manual - kanwal rekhi · code::block manual for cs101x course ... indian institute of...

60
Code::Block manual for CS101x course Department of Computer Science and Engineering Indian Institute of Technology - Bombay Mumbai - 400076. April 9, 2014

Upload: vukhanh

Post on 24-May-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

CodeBlock manual

for CS101x course

Department of Computer Science and EngineeringIndian Institute of Technology - Bombay

Mumbai - 400076

April 9 2014

Contents

1 Introduction 111 CodeBlocks 112 Simplecpp 1

2 CodeBlock IDE 1

3 Working with CodeBlock on Windows 631 Installation of CodeBlock 632 Installation of Simplecpp 1233 Writing a new CC++ Program 14

331 Non-Graphic Project 14332 Graphic Project using graphicsh 22333 Graphic Project using simplecpp 26

34 Building the Project 3335 Opening existing programproject 34

4 Working with CodeBlock on Ubuntu 3541 Installation of CodeBlocks 3542 Installation of packages for graphicsh header file 3643 Installation of Simplecpp 3644 Writing a new cc++ program 4145 Building the Project 45

451 Non-Graphics Project 45452 Graphics Project using graphicsh 45453 Graphics Project using simplecpp 50

46 Opening Existing ProgramProject 51

A Code used for Windows 53A1 helloworldc 53A2 linec 53A3 3polycpp 53

B Code used for Ubuntu 54B1 helloworldc 54B2 linec 54B3 3polycpp 54

C Enabling full logging in CodeBlock 55

i

List of Figures

1 CodeBlock IDE 12 Menu Bar 23 Main Toolbar 24 Debugger Toolbar 35 Compiler Toolbar 36 Manager 37 Editor StartHome Page 48 Shortcut to Create New Project or Open Existing Project 49 Shortcut to History of Projects Opened Using CodeBlocks 510 Logs 511 File association window 612 Click on ldquoRunrdquo 613 Welcome to the CodeBlocks-EP Setup Wizard screen 714 License Agreement 715 Information window 816 Providing location for CodeBlocks-EP installation 817 Providing folder for CodeBLocks-EP shortcuts 918 Creating desktop shortcut for CodeBlocks-EP 919 Installing CodeBlocks-EP 1020 Progress bar to show progress of installation 1021 Completing the installation process 1122 CodeBlock IDE in Windows 7 1123 Installation of simplecpp on windows 1224 Setup - Simplecpp 1225 Selecting CodeBlocks-EPrsquos installation folder 1326 Install 1327 Finish Simplecpp installation 1428 New form template 1429 New console application wizard 1530 Selecting language for the project 1531 Providing title and folder for the project 1632 Selecting compiler for the project 1633 Project node with no files 1734 Adding file to the project 1735 Selecting type of file to be added in the project 1836 Select checkbox to skip this window next time 1837 Select the language of the file added 1938 Details of file to be added 1939 Selecting the location and file name to be added 2040 Finalize details of file to be added 2041 Project node with lsquo+rsquo sign indicating it can be expanded 2142 Project node expanded 2143 Writing code in editor 2144 New form template 2245 New console application wizard 2246 Selecting language for the project 2347 WinBGIm project 2348 Providing title and folder for the project 2449 Selecting compiler for the project 2450 Finalize details of file to be added (for line project) 2551 Project node with lsquo+rsquo sign indicating it can be expanded 2552 Writing program in editor (line project) 2653 New from template 26

ii

54 Simplecpp project 2755 Providing title and folder for the project 2756 Selecting compiler for the project 2857 Empty project node in Management window 2858 Adding files to empty project node 2959 Selecting cc++ source for project 2960 Selecting language for the file to be added 3061 Giving location and name of the file to be added 3062 Finalize details of file to be added 3163 Project node with lsquo+rsquo sign indicating it can be expanded 3164 opening file in editor 3265 coding 3266 Output of hello world project 3367 Output of line project 3368 Output of 3poly project 3369 Selecting Open under file in Menu Bar 3470 Select file with cbp extension to open an existing project 3471 CodeBlock in Ubuntu Software Center 3572 Installing CodeBlock using command line 3573 Installing simplecpp 3774 location of simplecpps++ 3775 Copying the compiler 3776 Compiler and debugger settings 3877 Changes to be made in Toolchain Executables 3978 Simplecpprsquos directory 4079 Additional Paths settings 4080 Starting a new project 4181 Selecting the language for project 4182 Title for Project 4283 Selecting Compiler to Compile the Program 4284 Selecting simplecpp for projects including simplecpp 4385 Project Node when Expanded 4386 Project Node when Expanded for helloworldc (with code shown in editor) 4487 Project node when expanded for linec (with code shown in editor) 4488 Project node when expanded for 3polycpp (with code shown in editor) 4589 Output for helloworldc 4590 Project build options 4691 Linker settings (Add Libraries) 4692 Interface for adding libraries 4793 Fileslibraries to be added for graphic projects 4794 Relative or absolute path for fileslibraries 4895 libraries selected 4896 Libraries added to project 4997 Output for linec 4998 Output for 3polycpp 5099 Select file with cbp extension to open an existing project 51

iii

1 Introduction

11 CodeBlocks

ldquoCodeBlocks is a free C++ IDE built to meet the most demanding needs of its usersrdquo [1] Developed bylsquoThe CodeBlocks Teamrsquo CodeBlock is a free open-source [2] and cross-platform IDE which supportsvarious free compilers It is built around plugin framework which allows functionality of CodeBlock tobe extended by installing appropriate plugins Plugins required for compiling and debugging are alreadyprovided by default This manual is prepared after installing and testing CodeBlock on Ubuntu 12041

and Windows 72

12 Simplecpp

Simplecpp is a package used to write and execute turtle based non-graphicgraphic programs Simplecppis a package developed by Prof Abhiram Ranade at IIT Bombay and the book on lsquoAn Introductionto Programming through C++rsquo by Prof Abhiram Ranade uses simplecpp to explain basic program-ming For more information please refer to the Chapter 1 of the book Simplecpp is integrated withCodeBlocks and the simplecpp programs are tested with CodeBlocks on Windows 7 and Ubuntu 1204

2 CodeBlock IDE

CodeBlock IDE is shown in figure 1 (Ubuntu 1204) The main parts of CodeBlock along with figuresare discussed below

Figure 1 CodeBlock IDE

1Ubuntu 1204 with intel RcopyCore TMi3-2120 CPU 330GHzx4 processor 4 GB RAM and 32-bit architecture and 64bit architecture

2Windows 7 with intel RcopyCore TMi3-2120 CPU 330GHzx4 processor 4 GB RAM and 32-bit architecture

1

1 Menu barMenu bar is shown in figure 2 Menu bar can be toggled using F10 Few important link in menubar are described below (described from left to right)

Figure 2 Menu Bar

(a) File File menu link contains options to create a new project open an already existing projectsave file save project save workspace and save everything It also contains options for closinga single file closing a project or closing entire workspace Other options in File are to printexport and quit the CodeBlock

(b) Edit All the editing options required for editor are provided in Edit

(c) View This menu link contains link for various perspectives and toolbars along with managerlogs script console status bar full screen

(d) Project Options related to the project is provided in this link which includes configuring buildoptions along with options for adding files removing files and autoversioning of project

(e) Build Options for building the project compiling a single file running the project buildingand running the project rebuilding the project and cleaning the project is provided in buildOptions for Building rebuilding and cleaning the entire workspace is also provided along withoptions to select target (debugrelease) and analysing error one by one

(f) Debug Various Debugging options are provided in this link

(g) Plugins Various plugins can be executed using this link The link to manage the plugins isalso provided here

(h) Settings This contains link for various settings setting related to Environment EditorCompiler and debugger Global Variables and Scripting Script to be executed duringCodeBlock start-up can also be edited here

(i) Help It contains information about CodeBlock version tips which can be toggled to bedisplayed at start-up and information about various plugins

2 Main tool barMain tool bar is shown in figure 3 The buttons in Main toolbar are (from left to right)

Figure 3 Main Toolbar

(a) New File For creating a new project

(b) Open For opening an already created project

(c) Save To save the file open in active editor (active editor means the editor tab in focus)

(d) Save all files To save all the files for the currentselected project

(e) Undo To undo the executed action

(f) Redo To redo the undone action

(g) Cut To cut the selectedhighlighted part in editor

(h) Copy To copy the selectedhighlighted part in editor

(i) Paste To paste the cutcopy message in editor

(j) Find To find required text in the file in active editor

2

(k) Replace To replace required text in the file in active editor by some alternate text

3 Debugger tool barDebugger tool bar is shown in figure 4 Debugger tool bar is used to debug the currentselectedproject The buttons in debugger toolbar are (from left to right) DebugContinue Run to cursorNext lineNext instruction Step into Step out Stop debugger Debugging Windows and Variousinfo You will be able to understand the use of this buttons by rigorous practise of debuggingvarious projects

Figure 4 Debugger Toolbar

4 Compiler tool barCompiler tool bar is shown in figure 5 and is used in buildingcompilingrunning the currentse-lected project The buttons in Compiler toolbar are (from left to right)

Figure 5 Compiler Toolbar

(a) Build For building the currentselected project

(b) Run For running the currentselected project

(c) Build and run For building and running the currentselected project

(d) Rebuild For rebuilding the currentselected project

(e) Abort For aborting the build process for the currentselected project

(f) Build target For defining the type of build target for currentselected project either debugor release

5 ManagerManager is shown in figure 6 It is labelled as Management This window provides the list of allthe open projects and files for easy access to any required file of any project

Figure 6 Manager

6 EditorEditor is shown in figure 7 Here all the coding work will take place It is provided in tabbed

3

fashion to work with many files at once When no project is open the start page or home page isdisplayed in editor The links given in start page is divided into two parts and explained below

Figure 7 Editor StartHome Page

7 Figure 8 is short-cut on Starting page of IDE for creating a new project and opening an alreadycreated project It also contains link for CodeBlock forum where many useful resources can befound along with other useful discussions The link points to url httpforumscodeblocksorgThe second and third link points to BerLiOS Developer Site aims at enriching the Open Sourcecommunity by providing a centralized place for Open Source Developers to control and manageOpen Source Software Development

Figure 8 Shortcut to Create New Project or Open Existing Project

8 Figure 9 is short-cut to list of projects and files already opened in the IDE It is link to few projectsand files from history of IDE

4

Figure 9 Shortcut to History of Projects Opened Using CodeBlocks

9 LogsLog window is shown in figure 6 It is labelled as lsquoLogs amp othersrsquo This window acts as log forvarious actions performed in IDE All logs related to various activities can be checked at appropriatewindows

Figure 10 Logs

5

3 Working with CodeBlock on Windows

In this section we discuss writing and building of three projects First project (hello worldc) is a simpleprogram which displays hello world on output The second project (linec) uses graphicsh header fileand displays a line The third project (3polycpp) uses simplecpp package and draws three polygons onoutput For Windows (Windows 7) we will be using lsquoCodeBlocks-EPrsquo CodeBlocks-EP comeswith integrated WinBGIm (stands for Windows Borland Graphics Interface) In Windows WinBGIm isrequired to run the programs with graphicsh header file When CodeBlocks-EP is run for first time a lsquofileassociation windowrsquo is displayed as shown in figure 11 Select 3rd option ldquoYes associate CodeBlockswith cc++ file typesrdquo or 4th option ldquoYes associate CodeBlocks with every supported type(includingproject files from other IDEs)rdquo and click lsquoOKrsquo

Figure 11 File association window

31 Installation of CodeBlock

CodeBlock used for windows is CodeBlocks-EP (stands for CodeBlocks - EDU Portable) WinBGIm(Borland Graphics Interface) required to run programs with graphicsh header is already integrated inCodeBlocks-EP Download Codeblocks-EP from httpcodeblockscodecutterorg The installationsteps are as given below

1 Download CodeBlock-EP installer from the link given above and browse to the appropriate di-rectory where the installer is downloaded Click the exe file downloaded and window as shown infigure 12 will pop up Click lsquoRunrsquo

Figure 12 Click on ldquoRunrdquo

6

2 A new window appears as shown in figure 13 Click lsquoNextrsquo

Figure 13 Welcome to the CodeBlocks-EP Setup Wizard screen

3 The third windows that appears is of license agreement as shown in figure 14 Select ldquoI accept theagreementrdquo and click lsquoNextrsquo

Figure 14 License Agreement

7

4 The next window displays some important information (shown in figure 15) regarding CodeBlock-EP Kindly go through information and click on ldquoNextrdquo

Figure 15 Information window

5 Next window asks for location where the CodeBlock-EP will be installed The default location willbe CProgram FilesCodeBlocks-EP Figure 16 shows the location provided for CodeBlocks-EP installation Provide appropriate location and click on ldquoNextrdquo

Figure 16 Providing location for CodeBlocks-EP installation

8

Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar Click onldquoNextrdquo

Figure 17 Providing folder for CodeBLocks-EP shortcuts

Select the checkbox lsquoCreate a desktop iconrsquo as shown in Figure 18 Click lsquoNextrsquo

Figure 18 Creating desktop shortcut for CodeBlocks-EP

9

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

Contents

1 Introduction 111 CodeBlocks 112 Simplecpp 1

2 CodeBlock IDE 1

3 Working with CodeBlock on Windows 631 Installation of CodeBlock 632 Installation of Simplecpp 1233 Writing a new CC++ Program 14

331 Non-Graphic Project 14332 Graphic Project using graphicsh 22333 Graphic Project using simplecpp 26

34 Building the Project 3335 Opening existing programproject 34

4 Working with CodeBlock on Ubuntu 3541 Installation of CodeBlocks 3542 Installation of packages for graphicsh header file 3643 Installation of Simplecpp 3644 Writing a new cc++ program 4145 Building the Project 45

451 Non-Graphics Project 45452 Graphics Project using graphicsh 45453 Graphics Project using simplecpp 50

46 Opening Existing ProgramProject 51

A Code used for Windows 53A1 helloworldc 53A2 linec 53A3 3polycpp 53

B Code used for Ubuntu 54B1 helloworldc 54B2 linec 54B3 3polycpp 54

C Enabling full logging in CodeBlock 55

i

List of Figures

1 CodeBlock IDE 12 Menu Bar 23 Main Toolbar 24 Debugger Toolbar 35 Compiler Toolbar 36 Manager 37 Editor StartHome Page 48 Shortcut to Create New Project or Open Existing Project 49 Shortcut to History of Projects Opened Using CodeBlocks 510 Logs 511 File association window 612 Click on ldquoRunrdquo 613 Welcome to the CodeBlocks-EP Setup Wizard screen 714 License Agreement 715 Information window 816 Providing location for CodeBlocks-EP installation 817 Providing folder for CodeBLocks-EP shortcuts 918 Creating desktop shortcut for CodeBlocks-EP 919 Installing CodeBlocks-EP 1020 Progress bar to show progress of installation 1021 Completing the installation process 1122 CodeBlock IDE in Windows 7 1123 Installation of simplecpp on windows 1224 Setup - Simplecpp 1225 Selecting CodeBlocks-EPrsquos installation folder 1326 Install 1327 Finish Simplecpp installation 1428 New form template 1429 New console application wizard 1530 Selecting language for the project 1531 Providing title and folder for the project 1632 Selecting compiler for the project 1633 Project node with no files 1734 Adding file to the project 1735 Selecting type of file to be added in the project 1836 Select checkbox to skip this window next time 1837 Select the language of the file added 1938 Details of file to be added 1939 Selecting the location and file name to be added 2040 Finalize details of file to be added 2041 Project node with lsquo+rsquo sign indicating it can be expanded 2142 Project node expanded 2143 Writing code in editor 2144 New form template 2245 New console application wizard 2246 Selecting language for the project 2347 WinBGIm project 2348 Providing title and folder for the project 2449 Selecting compiler for the project 2450 Finalize details of file to be added (for line project) 2551 Project node with lsquo+rsquo sign indicating it can be expanded 2552 Writing program in editor (line project) 2653 New from template 26

ii

54 Simplecpp project 2755 Providing title and folder for the project 2756 Selecting compiler for the project 2857 Empty project node in Management window 2858 Adding files to empty project node 2959 Selecting cc++ source for project 2960 Selecting language for the file to be added 3061 Giving location and name of the file to be added 3062 Finalize details of file to be added 3163 Project node with lsquo+rsquo sign indicating it can be expanded 3164 opening file in editor 3265 coding 3266 Output of hello world project 3367 Output of line project 3368 Output of 3poly project 3369 Selecting Open under file in Menu Bar 3470 Select file with cbp extension to open an existing project 3471 CodeBlock in Ubuntu Software Center 3572 Installing CodeBlock using command line 3573 Installing simplecpp 3774 location of simplecpps++ 3775 Copying the compiler 3776 Compiler and debugger settings 3877 Changes to be made in Toolchain Executables 3978 Simplecpprsquos directory 4079 Additional Paths settings 4080 Starting a new project 4181 Selecting the language for project 4182 Title for Project 4283 Selecting Compiler to Compile the Program 4284 Selecting simplecpp for projects including simplecpp 4385 Project Node when Expanded 4386 Project Node when Expanded for helloworldc (with code shown in editor) 4487 Project node when expanded for linec (with code shown in editor) 4488 Project node when expanded for 3polycpp (with code shown in editor) 4589 Output for helloworldc 4590 Project build options 4691 Linker settings (Add Libraries) 4692 Interface for adding libraries 4793 Fileslibraries to be added for graphic projects 4794 Relative or absolute path for fileslibraries 4895 libraries selected 4896 Libraries added to project 4997 Output for linec 4998 Output for 3polycpp 5099 Select file with cbp extension to open an existing project 51

iii

1 Introduction

11 CodeBlocks

ldquoCodeBlocks is a free C++ IDE built to meet the most demanding needs of its usersrdquo [1] Developed bylsquoThe CodeBlocks Teamrsquo CodeBlock is a free open-source [2] and cross-platform IDE which supportsvarious free compilers It is built around plugin framework which allows functionality of CodeBlock tobe extended by installing appropriate plugins Plugins required for compiling and debugging are alreadyprovided by default This manual is prepared after installing and testing CodeBlock on Ubuntu 12041

and Windows 72

12 Simplecpp

Simplecpp is a package used to write and execute turtle based non-graphicgraphic programs Simplecppis a package developed by Prof Abhiram Ranade at IIT Bombay and the book on lsquoAn Introductionto Programming through C++rsquo by Prof Abhiram Ranade uses simplecpp to explain basic program-ming For more information please refer to the Chapter 1 of the book Simplecpp is integrated withCodeBlocks and the simplecpp programs are tested with CodeBlocks on Windows 7 and Ubuntu 1204

2 CodeBlock IDE

CodeBlock IDE is shown in figure 1 (Ubuntu 1204) The main parts of CodeBlock along with figuresare discussed below

Figure 1 CodeBlock IDE

1Ubuntu 1204 with intel RcopyCore TMi3-2120 CPU 330GHzx4 processor 4 GB RAM and 32-bit architecture and 64bit architecture

2Windows 7 with intel RcopyCore TMi3-2120 CPU 330GHzx4 processor 4 GB RAM and 32-bit architecture

1

1 Menu barMenu bar is shown in figure 2 Menu bar can be toggled using F10 Few important link in menubar are described below (described from left to right)

Figure 2 Menu Bar

(a) File File menu link contains options to create a new project open an already existing projectsave file save project save workspace and save everything It also contains options for closinga single file closing a project or closing entire workspace Other options in File are to printexport and quit the CodeBlock

(b) Edit All the editing options required for editor are provided in Edit

(c) View This menu link contains link for various perspectives and toolbars along with managerlogs script console status bar full screen

(d) Project Options related to the project is provided in this link which includes configuring buildoptions along with options for adding files removing files and autoversioning of project

(e) Build Options for building the project compiling a single file running the project buildingand running the project rebuilding the project and cleaning the project is provided in buildOptions for Building rebuilding and cleaning the entire workspace is also provided along withoptions to select target (debugrelease) and analysing error one by one

(f) Debug Various Debugging options are provided in this link

(g) Plugins Various plugins can be executed using this link The link to manage the plugins isalso provided here

(h) Settings This contains link for various settings setting related to Environment EditorCompiler and debugger Global Variables and Scripting Script to be executed duringCodeBlock start-up can also be edited here

(i) Help It contains information about CodeBlock version tips which can be toggled to bedisplayed at start-up and information about various plugins

2 Main tool barMain tool bar is shown in figure 3 The buttons in Main toolbar are (from left to right)

Figure 3 Main Toolbar

(a) New File For creating a new project

(b) Open For opening an already created project

(c) Save To save the file open in active editor (active editor means the editor tab in focus)

(d) Save all files To save all the files for the currentselected project

(e) Undo To undo the executed action

(f) Redo To redo the undone action

(g) Cut To cut the selectedhighlighted part in editor

(h) Copy To copy the selectedhighlighted part in editor

(i) Paste To paste the cutcopy message in editor

(j) Find To find required text in the file in active editor

2

(k) Replace To replace required text in the file in active editor by some alternate text

3 Debugger tool barDebugger tool bar is shown in figure 4 Debugger tool bar is used to debug the currentselectedproject The buttons in debugger toolbar are (from left to right) DebugContinue Run to cursorNext lineNext instruction Step into Step out Stop debugger Debugging Windows and Variousinfo You will be able to understand the use of this buttons by rigorous practise of debuggingvarious projects

Figure 4 Debugger Toolbar

4 Compiler tool barCompiler tool bar is shown in figure 5 and is used in buildingcompilingrunning the currentse-lected project The buttons in Compiler toolbar are (from left to right)

Figure 5 Compiler Toolbar

(a) Build For building the currentselected project

(b) Run For running the currentselected project

(c) Build and run For building and running the currentselected project

(d) Rebuild For rebuilding the currentselected project

(e) Abort For aborting the build process for the currentselected project

(f) Build target For defining the type of build target for currentselected project either debugor release

5 ManagerManager is shown in figure 6 It is labelled as Management This window provides the list of allthe open projects and files for easy access to any required file of any project

Figure 6 Manager

6 EditorEditor is shown in figure 7 Here all the coding work will take place It is provided in tabbed

3

fashion to work with many files at once When no project is open the start page or home page isdisplayed in editor The links given in start page is divided into two parts and explained below

Figure 7 Editor StartHome Page

7 Figure 8 is short-cut on Starting page of IDE for creating a new project and opening an alreadycreated project It also contains link for CodeBlock forum where many useful resources can befound along with other useful discussions The link points to url httpforumscodeblocksorgThe second and third link points to BerLiOS Developer Site aims at enriching the Open Sourcecommunity by providing a centralized place for Open Source Developers to control and manageOpen Source Software Development

Figure 8 Shortcut to Create New Project or Open Existing Project

8 Figure 9 is short-cut to list of projects and files already opened in the IDE It is link to few projectsand files from history of IDE

4

Figure 9 Shortcut to History of Projects Opened Using CodeBlocks

9 LogsLog window is shown in figure 6 It is labelled as lsquoLogs amp othersrsquo This window acts as log forvarious actions performed in IDE All logs related to various activities can be checked at appropriatewindows

Figure 10 Logs

5

3 Working with CodeBlock on Windows

In this section we discuss writing and building of three projects First project (hello worldc) is a simpleprogram which displays hello world on output The second project (linec) uses graphicsh header fileand displays a line The third project (3polycpp) uses simplecpp package and draws three polygons onoutput For Windows (Windows 7) we will be using lsquoCodeBlocks-EPrsquo CodeBlocks-EP comeswith integrated WinBGIm (stands for Windows Borland Graphics Interface) In Windows WinBGIm isrequired to run the programs with graphicsh header file When CodeBlocks-EP is run for first time a lsquofileassociation windowrsquo is displayed as shown in figure 11 Select 3rd option ldquoYes associate CodeBlockswith cc++ file typesrdquo or 4th option ldquoYes associate CodeBlocks with every supported type(includingproject files from other IDEs)rdquo and click lsquoOKrsquo

Figure 11 File association window

31 Installation of CodeBlock

CodeBlock used for windows is CodeBlocks-EP (stands for CodeBlocks - EDU Portable) WinBGIm(Borland Graphics Interface) required to run programs with graphicsh header is already integrated inCodeBlocks-EP Download Codeblocks-EP from httpcodeblockscodecutterorg The installationsteps are as given below

1 Download CodeBlock-EP installer from the link given above and browse to the appropriate di-rectory where the installer is downloaded Click the exe file downloaded and window as shown infigure 12 will pop up Click lsquoRunrsquo

Figure 12 Click on ldquoRunrdquo

6

2 A new window appears as shown in figure 13 Click lsquoNextrsquo

Figure 13 Welcome to the CodeBlocks-EP Setup Wizard screen

3 The third windows that appears is of license agreement as shown in figure 14 Select ldquoI accept theagreementrdquo and click lsquoNextrsquo

Figure 14 License Agreement

7

4 The next window displays some important information (shown in figure 15) regarding CodeBlock-EP Kindly go through information and click on ldquoNextrdquo

Figure 15 Information window

5 Next window asks for location where the CodeBlock-EP will be installed The default location willbe CProgram FilesCodeBlocks-EP Figure 16 shows the location provided for CodeBlocks-EP installation Provide appropriate location and click on ldquoNextrdquo

Figure 16 Providing location for CodeBlocks-EP installation

8

Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar Click onldquoNextrdquo

Figure 17 Providing folder for CodeBLocks-EP shortcuts

Select the checkbox lsquoCreate a desktop iconrsquo as shown in Figure 18 Click lsquoNextrsquo

Figure 18 Creating desktop shortcut for CodeBlocks-EP

9

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

List of Figures

1 CodeBlock IDE 12 Menu Bar 23 Main Toolbar 24 Debugger Toolbar 35 Compiler Toolbar 36 Manager 37 Editor StartHome Page 48 Shortcut to Create New Project or Open Existing Project 49 Shortcut to History of Projects Opened Using CodeBlocks 510 Logs 511 File association window 612 Click on ldquoRunrdquo 613 Welcome to the CodeBlocks-EP Setup Wizard screen 714 License Agreement 715 Information window 816 Providing location for CodeBlocks-EP installation 817 Providing folder for CodeBLocks-EP shortcuts 918 Creating desktop shortcut for CodeBlocks-EP 919 Installing CodeBlocks-EP 1020 Progress bar to show progress of installation 1021 Completing the installation process 1122 CodeBlock IDE in Windows 7 1123 Installation of simplecpp on windows 1224 Setup - Simplecpp 1225 Selecting CodeBlocks-EPrsquos installation folder 1326 Install 1327 Finish Simplecpp installation 1428 New form template 1429 New console application wizard 1530 Selecting language for the project 1531 Providing title and folder for the project 1632 Selecting compiler for the project 1633 Project node with no files 1734 Adding file to the project 1735 Selecting type of file to be added in the project 1836 Select checkbox to skip this window next time 1837 Select the language of the file added 1938 Details of file to be added 1939 Selecting the location and file name to be added 2040 Finalize details of file to be added 2041 Project node with lsquo+rsquo sign indicating it can be expanded 2142 Project node expanded 2143 Writing code in editor 2144 New form template 2245 New console application wizard 2246 Selecting language for the project 2347 WinBGIm project 2348 Providing title and folder for the project 2449 Selecting compiler for the project 2450 Finalize details of file to be added (for line project) 2551 Project node with lsquo+rsquo sign indicating it can be expanded 2552 Writing program in editor (line project) 2653 New from template 26

ii

54 Simplecpp project 2755 Providing title and folder for the project 2756 Selecting compiler for the project 2857 Empty project node in Management window 2858 Adding files to empty project node 2959 Selecting cc++ source for project 2960 Selecting language for the file to be added 3061 Giving location and name of the file to be added 3062 Finalize details of file to be added 3163 Project node with lsquo+rsquo sign indicating it can be expanded 3164 opening file in editor 3265 coding 3266 Output of hello world project 3367 Output of line project 3368 Output of 3poly project 3369 Selecting Open under file in Menu Bar 3470 Select file with cbp extension to open an existing project 3471 CodeBlock in Ubuntu Software Center 3572 Installing CodeBlock using command line 3573 Installing simplecpp 3774 location of simplecpps++ 3775 Copying the compiler 3776 Compiler and debugger settings 3877 Changes to be made in Toolchain Executables 3978 Simplecpprsquos directory 4079 Additional Paths settings 4080 Starting a new project 4181 Selecting the language for project 4182 Title for Project 4283 Selecting Compiler to Compile the Program 4284 Selecting simplecpp for projects including simplecpp 4385 Project Node when Expanded 4386 Project Node when Expanded for helloworldc (with code shown in editor) 4487 Project node when expanded for linec (with code shown in editor) 4488 Project node when expanded for 3polycpp (with code shown in editor) 4589 Output for helloworldc 4590 Project build options 4691 Linker settings (Add Libraries) 4692 Interface for adding libraries 4793 Fileslibraries to be added for graphic projects 4794 Relative or absolute path for fileslibraries 4895 libraries selected 4896 Libraries added to project 4997 Output for linec 4998 Output for 3polycpp 5099 Select file with cbp extension to open an existing project 51

iii

1 Introduction

11 CodeBlocks

ldquoCodeBlocks is a free C++ IDE built to meet the most demanding needs of its usersrdquo [1] Developed bylsquoThe CodeBlocks Teamrsquo CodeBlock is a free open-source [2] and cross-platform IDE which supportsvarious free compilers It is built around plugin framework which allows functionality of CodeBlock tobe extended by installing appropriate plugins Plugins required for compiling and debugging are alreadyprovided by default This manual is prepared after installing and testing CodeBlock on Ubuntu 12041

and Windows 72

12 Simplecpp

Simplecpp is a package used to write and execute turtle based non-graphicgraphic programs Simplecppis a package developed by Prof Abhiram Ranade at IIT Bombay and the book on lsquoAn Introductionto Programming through C++rsquo by Prof Abhiram Ranade uses simplecpp to explain basic program-ming For more information please refer to the Chapter 1 of the book Simplecpp is integrated withCodeBlocks and the simplecpp programs are tested with CodeBlocks on Windows 7 and Ubuntu 1204

2 CodeBlock IDE

CodeBlock IDE is shown in figure 1 (Ubuntu 1204) The main parts of CodeBlock along with figuresare discussed below

Figure 1 CodeBlock IDE

1Ubuntu 1204 with intel RcopyCore TMi3-2120 CPU 330GHzx4 processor 4 GB RAM and 32-bit architecture and 64bit architecture

2Windows 7 with intel RcopyCore TMi3-2120 CPU 330GHzx4 processor 4 GB RAM and 32-bit architecture

1

1 Menu barMenu bar is shown in figure 2 Menu bar can be toggled using F10 Few important link in menubar are described below (described from left to right)

Figure 2 Menu Bar

(a) File File menu link contains options to create a new project open an already existing projectsave file save project save workspace and save everything It also contains options for closinga single file closing a project or closing entire workspace Other options in File are to printexport and quit the CodeBlock

(b) Edit All the editing options required for editor are provided in Edit

(c) View This menu link contains link for various perspectives and toolbars along with managerlogs script console status bar full screen

(d) Project Options related to the project is provided in this link which includes configuring buildoptions along with options for adding files removing files and autoversioning of project

(e) Build Options for building the project compiling a single file running the project buildingand running the project rebuilding the project and cleaning the project is provided in buildOptions for Building rebuilding and cleaning the entire workspace is also provided along withoptions to select target (debugrelease) and analysing error one by one

(f) Debug Various Debugging options are provided in this link

(g) Plugins Various plugins can be executed using this link The link to manage the plugins isalso provided here

(h) Settings This contains link for various settings setting related to Environment EditorCompiler and debugger Global Variables and Scripting Script to be executed duringCodeBlock start-up can also be edited here

(i) Help It contains information about CodeBlock version tips which can be toggled to bedisplayed at start-up and information about various plugins

2 Main tool barMain tool bar is shown in figure 3 The buttons in Main toolbar are (from left to right)

Figure 3 Main Toolbar

(a) New File For creating a new project

(b) Open For opening an already created project

(c) Save To save the file open in active editor (active editor means the editor tab in focus)

(d) Save all files To save all the files for the currentselected project

(e) Undo To undo the executed action

(f) Redo To redo the undone action

(g) Cut To cut the selectedhighlighted part in editor

(h) Copy To copy the selectedhighlighted part in editor

(i) Paste To paste the cutcopy message in editor

(j) Find To find required text in the file in active editor

2

(k) Replace To replace required text in the file in active editor by some alternate text

3 Debugger tool barDebugger tool bar is shown in figure 4 Debugger tool bar is used to debug the currentselectedproject The buttons in debugger toolbar are (from left to right) DebugContinue Run to cursorNext lineNext instruction Step into Step out Stop debugger Debugging Windows and Variousinfo You will be able to understand the use of this buttons by rigorous practise of debuggingvarious projects

Figure 4 Debugger Toolbar

4 Compiler tool barCompiler tool bar is shown in figure 5 and is used in buildingcompilingrunning the currentse-lected project The buttons in Compiler toolbar are (from left to right)

Figure 5 Compiler Toolbar

(a) Build For building the currentselected project

(b) Run For running the currentselected project

(c) Build and run For building and running the currentselected project

(d) Rebuild For rebuilding the currentselected project

(e) Abort For aborting the build process for the currentselected project

(f) Build target For defining the type of build target for currentselected project either debugor release

5 ManagerManager is shown in figure 6 It is labelled as Management This window provides the list of allthe open projects and files for easy access to any required file of any project

Figure 6 Manager

6 EditorEditor is shown in figure 7 Here all the coding work will take place It is provided in tabbed

3

fashion to work with many files at once When no project is open the start page or home page isdisplayed in editor The links given in start page is divided into two parts and explained below

Figure 7 Editor StartHome Page

7 Figure 8 is short-cut on Starting page of IDE for creating a new project and opening an alreadycreated project It also contains link for CodeBlock forum where many useful resources can befound along with other useful discussions The link points to url httpforumscodeblocksorgThe second and third link points to BerLiOS Developer Site aims at enriching the Open Sourcecommunity by providing a centralized place for Open Source Developers to control and manageOpen Source Software Development

Figure 8 Shortcut to Create New Project or Open Existing Project

8 Figure 9 is short-cut to list of projects and files already opened in the IDE It is link to few projectsand files from history of IDE

4

Figure 9 Shortcut to History of Projects Opened Using CodeBlocks

9 LogsLog window is shown in figure 6 It is labelled as lsquoLogs amp othersrsquo This window acts as log forvarious actions performed in IDE All logs related to various activities can be checked at appropriatewindows

Figure 10 Logs

5

3 Working with CodeBlock on Windows

In this section we discuss writing and building of three projects First project (hello worldc) is a simpleprogram which displays hello world on output The second project (linec) uses graphicsh header fileand displays a line The third project (3polycpp) uses simplecpp package and draws three polygons onoutput For Windows (Windows 7) we will be using lsquoCodeBlocks-EPrsquo CodeBlocks-EP comeswith integrated WinBGIm (stands for Windows Borland Graphics Interface) In Windows WinBGIm isrequired to run the programs with graphicsh header file When CodeBlocks-EP is run for first time a lsquofileassociation windowrsquo is displayed as shown in figure 11 Select 3rd option ldquoYes associate CodeBlockswith cc++ file typesrdquo or 4th option ldquoYes associate CodeBlocks with every supported type(includingproject files from other IDEs)rdquo and click lsquoOKrsquo

Figure 11 File association window

31 Installation of CodeBlock

CodeBlock used for windows is CodeBlocks-EP (stands for CodeBlocks - EDU Portable) WinBGIm(Borland Graphics Interface) required to run programs with graphicsh header is already integrated inCodeBlocks-EP Download Codeblocks-EP from httpcodeblockscodecutterorg The installationsteps are as given below

1 Download CodeBlock-EP installer from the link given above and browse to the appropriate di-rectory where the installer is downloaded Click the exe file downloaded and window as shown infigure 12 will pop up Click lsquoRunrsquo

Figure 12 Click on ldquoRunrdquo

6

2 A new window appears as shown in figure 13 Click lsquoNextrsquo

Figure 13 Welcome to the CodeBlocks-EP Setup Wizard screen

3 The third windows that appears is of license agreement as shown in figure 14 Select ldquoI accept theagreementrdquo and click lsquoNextrsquo

Figure 14 License Agreement

7

4 The next window displays some important information (shown in figure 15) regarding CodeBlock-EP Kindly go through information and click on ldquoNextrdquo

Figure 15 Information window

5 Next window asks for location where the CodeBlock-EP will be installed The default location willbe CProgram FilesCodeBlocks-EP Figure 16 shows the location provided for CodeBlocks-EP installation Provide appropriate location and click on ldquoNextrdquo

Figure 16 Providing location for CodeBlocks-EP installation

8

Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar Click onldquoNextrdquo

Figure 17 Providing folder for CodeBLocks-EP shortcuts

Select the checkbox lsquoCreate a desktop iconrsquo as shown in Figure 18 Click lsquoNextrsquo

Figure 18 Creating desktop shortcut for CodeBlocks-EP

9

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

54 Simplecpp project 2755 Providing title and folder for the project 2756 Selecting compiler for the project 2857 Empty project node in Management window 2858 Adding files to empty project node 2959 Selecting cc++ source for project 2960 Selecting language for the file to be added 3061 Giving location and name of the file to be added 3062 Finalize details of file to be added 3163 Project node with lsquo+rsquo sign indicating it can be expanded 3164 opening file in editor 3265 coding 3266 Output of hello world project 3367 Output of line project 3368 Output of 3poly project 3369 Selecting Open under file in Menu Bar 3470 Select file with cbp extension to open an existing project 3471 CodeBlock in Ubuntu Software Center 3572 Installing CodeBlock using command line 3573 Installing simplecpp 3774 location of simplecpps++ 3775 Copying the compiler 3776 Compiler and debugger settings 3877 Changes to be made in Toolchain Executables 3978 Simplecpprsquos directory 4079 Additional Paths settings 4080 Starting a new project 4181 Selecting the language for project 4182 Title for Project 4283 Selecting Compiler to Compile the Program 4284 Selecting simplecpp for projects including simplecpp 4385 Project Node when Expanded 4386 Project Node when Expanded for helloworldc (with code shown in editor) 4487 Project node when expanded for linec (with code shown in editor) 4488 Project node when expanded for 3polycpp (with code shown in editor) 4589 Output for helloworldc 4590 Project build options 4691 Linker settings (Add Libraries) 4692 Interface for adding libraries 4793 Fileslibraries to be added for graphic projects 4794 Relative or absolute path for fileslibraries 4895 libraries selected 4896 Libraries added to project 4997 Output for linec 4998 Output for 3polycpp 5099 Select file with cbp extension to open an existing project 51

iii

1 Introduction

11 CodeBlocks

ldquoCodeBlocks is a free C++ IDE built to meet the most demanding needs of its usersrdquo [1] Developed bylsquoThe CodeBlocks Teamrsquo CodeBlock is a free open-source [2] and cross-platform IDE which supportsvarious free compilers It is built around plugin framework which allows functionality of CodeBlock tobe extended by installing appropriate plugins Plugins required for compiling and debugging are alreadyprovided by default This manual is prepared after installing and testing CodeBlock on Ubuntu 12041

and Windows 72

12 Simplecpp

Simplecpp is a package used to write and execute turtle based non-graphicgraphic programs Simplecppis a package developed by Prof Abhiram Ranade at IIT Bombay and the book on lsquoAn Introductionto Programming through C++rsquo by Prof Abhiram Ranade uses simplecpp to explain basic program-ming For more information please refer to the Chapter 1 of the book Simplecpp is integrated withCodeBlocks and the simplecpp programs are tested with CodeBlocks on Windows 7 and Ubuntu 1204

2 CodeBlock IDE

CodeBlock IDE is shown in figure 1 (Ubuntu 1204) The main parts of CodeBlock along with figuresare discussed below

Figure 1 CodeBlock IDE

1Ubuntu 1204 with intel RcopyCore TMi3-2120 CPU 330GHzx4 processor 4 GB RAM and 32-bit architecture and 64bit architecture

2Windows 7 with intel RcopyCore TMi3-2120 CPU 330GHzx4 processor 4 GB RAM and 32-bit architecture

1

1 Menu barMenu bar is shown in figure 2 Menu bar can be toggled using F10 Few important link in menubar are described below (described from left to right)

Figure 2 Menu Bar

(a) File File menu link contains options to create a new project open an already existing projectsave file save project save workspace and save everything It also contains options for closinga single file closing a project or closing entire workspace Other options in File are to printexport and quit the CodeBlock

(b) Edit All the editing options required for editor are provided in Edit

(c) View This menu link contains link for various perspectives and toolbars along with managerlogs script console status bar full screen

(d) Project Options related to the project is provided in this link which includes configuring buildoptions along with options for adding files removing files and autoversioning of project

(e) Build Options for building the project compiling a single file running the project buildingand running the project rebuilding the project and cleaning the project is provided in buildOptions for Building rebuilding and cleaning the entire workspace is also provided along withoptions to select target (debugrelease) and analysing error one by one

(f) Debug Various Debugging options are provided in this link

(g) Plugins Various plugins can be executed using this link The link to manage the plugins isalso provided here

(h) Settings This contains link for various settings setting related to Environment EditorCompiler and debugger Global Variables and Scripting Script to be executed duringCodeBlock start-up can also be edited here

(i) Help It contains information about CodeBlock version tips which can be toggled to bedisplayed at start-up and information about various plugins

2 Main tool barMain tool bar is shown in figure 3 The buttons in Main toolbar are (from left to right)

Figure 3 Main Toolbar

(a) New File For creating a new project

(b) Open For opening an already created project

(c) Save To save the file open in active editor (active editor means the editor tab in focus)

(d) Save all files To save all the files for the currentselected project

(e) Undo To undo the executed action

(f) Redo To redo the undone action

(g) Cut To cut the selectedhighlighted part in editor

(h) Copy To copy the selectedhighlighted part in editor

(i) Paste To paste the cutcopy message in editor

(j) Find To find required text in the file in active editor

2

(k) Replace To replace required text in the file in active editor by some alternate text

3 Debugger tool barDebugger tool bar is shown in figure 4 Debugger tool bar is used to debug the currentselectedproject The buttons in debugger toolbar are (from left to right) DebugContinue Run to cursorNext lineNext instruction Step into Step out Stop debugger Debugging Windows and Variousinfo You will be able to understand the use of this buttons by rigorous practise of debuggingvarious projects

Figure 4 Debugger Toolbar

4 Compiler tool barCompiler tool bar is shown in figure 5 and is used in buildingcompilingrunning the currentse-lected project The buttons in Compiler toolbar are (from left to right)

Figure 5 Compiler Toolbar

(a) Build For building the currentselected project

(b) Run For running the currentselected project

(c) Build and run For building and running the currentselected project

(d) Rebuild For rebuilding the currentselected project

(e) Abort For aborting the build process for the currentselected project

(f) Build target For defining the type of build target for currentselected project either debugor release

5 ManagerManager is shown in figure 6 It is labelled as Management This window provides the list of allthe open projects and files for easy access to any required file of any project

Figure 6 Manager

6 EditorEditor is shown in figure 7 Here all the coding work will take place It is provided in tabbed

3

fashion to work with many files at once When no project is open the start page or home page isdisplayed in editor The links given in start page is divided into two parts and explained below

Figure 7 Editor StartHome Page

7 Figure 8 is short-cut on Starting page of IDE for creating a new project and opening an alreadycreated project It also contains link for CodeBlock forum where many useful resources can befound along with other useful discussions The link points to url httpforumscodeblocksorgThe second and third link points to BerLiOS Developer Site aims at enriching the Open Sourcecommunity by providing a centralized place for Open Source Developers to control and manageOpen Source Software Development

Figure 8 Shortcut to Create New Project or Open Existing Project

8 Figure 9 is short-cut to list of projects and files already opened in the IDE It is link to few projectsand files from history of IDE

4

Figure 9 Shortcut to History of Projects Opened Using CodeBlocks

9 LogsLog window is shown in figure 6 It is labelled as lsquoLogs amp othersrsquo This window acts as log forvarious actions performed in IDE All logs related to various activities can be checked at appropriatewindows

Figure 10 Logs

5

3 Working with CodeBlock on Windows

In this section we discuss writing and building of three projects First project (hello worldc) is a simpleprogram which displays hello world on output The second project (linec) uses graphicsh header fileand displays a line The third project (3polycpp) uses simplecpp package and draws three polygons onoutput For Windows (Windows 7) we will be using lsquoCodeBlocks-EPrsquo CodeBlocks-EP comeswith integrated WinBGIm (stands for Windows Borland Graphics Interface) In Windows WinBGIm isrequired to run the programs with graphicsh header file When CodeBlocks-EP is run for first time a lsquofileassociation windowrsquo is displayed as shown in figure 11 Select 3rd option ldquoYes associate CodeBlockswith cc++ file typesrdquo or 4th option ldquoYes associate CodeBlocks with every supported type(includingproject files from other IDEs)rdquo and click lsquoOKrsquo

Figure 11 File association window

31 Installation of CodeBlock

CodeBlock used for windows is CodeBlocks-EP (stands for CodeBlocks - EDU Portable) WinBGIm(Borland Graphics Interface) required to run programs with graphicsh header is already integrated inCodeBlocks-EP Download Codeblocks-EP from httpcodeblockscodecutterorg The installationsteps are as given below

1 Download CodeBlock-EP installer from the link given above and browse to the appropriate di-rectory where the installer is downloaded Click the exe file downloaded and window as shown infigure 12 will pop up Click lsquoRunrsquo

Figure 12 Click on ldquoRunrdquo

6

2 A new window appears as shown in figure 13 Click lsquoNextrsquo

Figure 13 Welcome to the CodeBlocks-EP Setup Wizard screen

3 The third windows that appears is of license agreement as shown in figure 14 Select ldquoI accept theagreementrdquo and click lsquoNextrsquo

Figure 14 License Agreement

7

4 The next window displays some important information (shown in figure 15) regarding CodeBlock-EP Kindly go through information and click on ldquoNextrdquo

Figure 15 Information window

5 Next window asks for location where the CodeBlock-EP will be installed The default location willbe CProgram FilesCodeBlocks-EP Figure 16 shows the location provided for CodeBlocks-EP installation Provide appropriate location and click on ldquoNextrdquo

Figure 16 Providing location for CodeBlocks-EP installation

8

Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar Click onldquoNextrdquo

Figure 17 Providing folder for CodeBLocks-EP shortcuts

Select the checkbox lsquoCreate a desktop iconrsquo as shown in Figure 18 Click lsquoNextrsquo

Figure 18 Creating desktop shortcut for CodeBlocks-EP

9

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

1 Introduction

11 CodeBlocks

ldquoCodeBlocks is a free C++ IDE built to meet the most demanding needs of its usersrdquo [1] Developed bylsquoThe CodeBlocks Teamrsquo CodeBlock is a free open-source [2] and cross-platform IDE which supportsvarious free compilers It is built around plugin framework which allows functionality of CodeBlock tobe extended by installing appropriate plugins Plugins required for compiling and debugging are alreadyprovided by default This manual is prepared after installing and testing CodeBlock on Ubuntu 12041

and Windows 72

12 Simplecpp

Simplecpp is a package used to write and execute turtle based non-graphicgraphic programs Simplecppis a package developed by Prof Abhiram Ranade at IIT Bombay and the book on lsquoAn Introductionto Programming through C++rsquo by Prof Abhiram Ranade uses simplecpp to explain basic program-ming For more information please refer to the Chapter 1 of the book Simplecpp is integrated withCodeBlocks and the simplecpp programs are tested with CodeBlocks on Windows 7 and Ubuntu 1204

2 CodeBlock IDE

CodeBlock IDE is shown in figure 1 (Ubuntu 1204) The main parts of CodeBlock along with figuresare discussed below

Figure 1 CodeBlock IDE

1Ubuntu 1204 with intel RcopyCore TMi3-2120 CPU 330GHzx4 processor 4 GB RAM and 32-bit architecture and 64bit architecture

2Windows 7 with intel RcopyCore TMi3-2120 CPU 330GHzx4 processor 4 GB RAM and 32-bit architecture

1

1 Menu barMenu bar is shown in figure 2 Menu bar can be toggled using F10 Few important link in menubar are described below (described from left to right)

Figure 2 Menu Bar

(a) File File menu link contains options to create a new project open an already existing projectsave file save project save workspace and save everything It also contains options for closinga single file closing a project or closing entire workspace Other options in File are to printexport and quit the CodeBlock

(b) Edit All the editing options required for editor are provided in Edit

(c) View This menu link contains link for various perspectives and toolbars along with managerlogs script console status bar full screen

(d) Project Options related to the project is provided in this link which includes configuring buildoptions along with options for adding files removing files and autoversioning of project

(e) Build Options for building the project compiling a single file running the project buildingand running the project rebuilding the project and cleaning the project is provided in buildOptions for Building rebuilding and cleaning the entire workspace is also provided along withoptions to select target (debugrelease) and analysing error one by one

(f) Debug Various Debugging options are provided in this link

(g) Plugins Various plugins can be executed using this link The link to manage the plugins isalso provided here

(h) Settings This contains link for various settings setting related to Environment EditorCompiler and debugger Global Variables and Scripting Script to be executed duringCodeBlock start-up can also be edited here

(i) Help It contains information about CodeBlock version tips which can be toggled to bedisplayed at start-up and information about various plugins

2 Main tool barMain tool bar is shown in figure 3 The buttons in Main toolbar are (from left to right)

Figure 3 Main Toolbar

(a) New File For creating a new project

(b) Open For opening an already created project

(c) Save To save the file open in active editor (active editor means the editor tab in focus)

(d) Save all files To save all the files for the currentselected project

(e) Undo To undo the executed action

(f) Redo To redo the undone action

(g) Cut To cut the selectedhighlighted part in editor

(h) Copy To copy the selectedhighlighted part in editor

(i) Paste To paste the cutcopy message in editor

(j) Find To find required text in the file in active editor

2

(k) Replace To replace required text in the file in active editor by some alternate text

3 Debugger tool barDebugger tool bar is shown in figure 4 Debugger tool bar is used to debug the currentselectedproject The buttons in debugger toolbar are (from left to right) DebugContinue Run to cursorNext lineNext instruction Step into Step out Stop debugger Debugging Windows and Variousinfo You will be able to understand the use of this buttons by rigorous practise of debuggingvarious projects

Figure 4 Debugger Toolbar

4 Compiler tool barCompiler tool bar is shown in figure 5 and is used in buildingcompilingrunning the currentse-lected project The buttons in Compiler toolbar are (from left to right)

Figure 5 Compiler Toolbar

(a) Build For building the currentselected project

(b) Run For running the currentselected project

(c) Build and run For building and running the currentselected project

(d) Rebuild For rebuilding the currentselected project

(e) Abort For aborting the build process for the currentselected project

(f) Build target For defining the type of build target for currentselected project either debugor release

5 ManagerManager is shown in figure 6 It is labelled as Management This window provides the list of allthe open projects and files for easy access to any required file of any project

Figure 6 Manager

6 EditorEditor is shown in figure 7 Here all the coding work will take place It is provided in tabbed

3

fashion to work with many files at once When no project is open the start page or home page isdisplayed in editor The links given in start page is divided into two parts and explained below

Figure 7 Editor StartHome Page

7 Figure 8 is short-cut on Starting page of IDE for creating a new project and opening an alreadycreated project It also contains link for CodeBlock forum where many useful resources can befound along with other useful discussions The link points to url httpforumscodeblocksorgThe second and third link points to BerLiOS Developer Site aims at enriching the Open Sourcecommunity by providing a centralized place for Open Source Developers to control and manageOpen Source Software Development

Figure 8 Shortcut to Create New Project or Open Existing Project

8 Figure 9 is short-cut to list of projects and files already opened in the IDE It is link to few projectsand files from history of IDE

4

Figure 9 Shortcut to History of Projects Opened Using CodeBlocks

9 LogsLog window is shown in figure 6 It is labelled as lsquoLogs amp othersrsquo This window acts as log forvarious actions performed in IDE All logs related to various activities can be checked at appropriatewindows

Figure 10 Logs

5

3 Working with CodeBlock on Windows

In this section we discuss writing and building of three projects First project (hello worldc) is a simpleprogram which displays hello world on output The second project (linec) uses graphicsh header fileand displays a line The third project (3polycpp) uses simplecpp package and draws three polygons onoutput For Windows (Windows 7) we will be using lsquoCodeBlocks-EPrsquo CodeBlocks-EP comeswith integrated WinBGIm (stands for Windows Borland Graphics Interface) In Windows WinBGIm isrequired to run the programs with graphicsh header file When CodeBlocks-EP is run for first time a lsquofileassociation windowrsquo is displayed as shown in figure 11 Select 3rd option ldquoYes associate CodeBlockswith cc++ file typesrdquo or 4th option ldquoYes associate CodeBlocks with every supported type(includingproject files from other IDEs)rdquo and click lsquoOKrsquo

Figure 11 File association window

31 Installation of CodeBlock

CodeBlock used for windows is CodeBlocks-EP (stands for CodeBlocks - EDU Portable) WinBGIm(Borland Graphics Interface) required to run programs with graphicsh header is already integrated inCodeBlocks-EP Download Codeblocks-EP from httpcodeblockscodecutterorg The installationsteps are as given below

1 Download CodeBlock-EP installer from the link given above and browse to the appropriate di-rectory where the installer is downloaded Click the exe file downloaded and window as shown infigure 12 will pop up Click lsquoRunrsquo

Figure 12 Click on ldquoRunrdquo

6

2 A new window appears as shown in figure 13 Click lsquoNextrsquo

Figure 13 Welcome to the CodeBlocks-EP Setup Wizard screen

3 The third windows that appears is of license agreement as shown in figure 14 Select ldquoI accept theagreementrdquo and click lsquoNextrsquo

Figure 14 License Agreement

7

4 The next window displays some important information (shown in figure 15) regarding CodeBlock-EP Kindly go through information and click on ldquoNextrdquo

Figure 15 Information window

5 Next window asks for location where the CodeBlock-EP will be installed The default location willbe CProgram FilesCodeBlocks-EP Figure 16 shows the location provided for CodeBlocks-EP installation Provide appropriate location and click on ldquoNextrdquo

Figure 16 Providing location for CodeBlocks-EP installation

8

Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar Click onldquoNextrdquo

Figure 17 Providing folder for CodeBLocks-EP shortcuts

Select the checkbox lsquoCreate a desktop iconrsquo as shown in Figure 18 Click lsquoNextrsquo

Figure 18 Creating desktop shortcut for CodeBlocks-EP

9

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

1 Menu barMenu bar is shown in figure 2 Menu bar can be toggled using F10 Few important link in menubar are described below (described from left to right)

Figure 2 Menu Bar

(a) File File menu link contains options to create a new project open an already existing projectsave file save project save workspace and save everything It also contains options for closinga single file closing a project or closing entire workspace Other options in File are to printexport and quit the CodeBlock

(b) Edit All the editing options required for editor are provided in Edit

(c) View This menu link contains link for various perspectives and toolbars along with managerlogs script console status bar full screen

(d) Project Options related to the project is provided in this link which includes configuring buildoptions along with options for adding files removing files and autoversioning of project

(e) Build Options for building the project compiling a single file running the project buildingand running the project rebuilding the project and cleaning the project is provided in buildOptions for Building rebuilding and cleaning the entire workspace is also provided along withoptions to select target (debugrelease) and analysing error one by one

(f) Debug Various Debugging options are provided in this link

(g) Plugins Various plugins can be executed using this link The link to manage the plugins isalso provided here

(h) Settings This contains link for various settings setting related to Environment EditorCompiler and debugger Global Variables and Scripting Script to be executed duringCodeBlock start-up can also be edited here

(i) Help It contains information about CodeBlock version tips which can be toggled to bedisplayed at start-up and information about various plugins

2 Main tool barMain tool bar is shown in figure 3 The buttons in Main toolbar are (from left to right)

Figure 3 Main Toolbar

(a) New File For creating a new project

(b) Open For opening an already created project

(c) Save To save the file open in active editor (active editor means the editor tab in focus)

(d) Save all files To save all the files for the currentselected project

(e) Undo To undo the executed action

(f) Redo To redo the undone action

(g) Cut To cut the selectedhighlighted part in editor

(h) Copy To copy the selectedhighlighted part in editor

(i) Paste To paste the cutcopy message in editor

(j) Find To find required text in the file in active editor

2

(k) Replace To replace required text in the file in active editor by some alternate text

3 Debugger tool barDebugger tool bar is shown in figure 4 Debugger tool bar is used to debug the currentselectedproject The buttons in debugger toolbar are (from left to right) DebugContinue Run to cursorNext lineNext instruction Step into Step out Stop debugger Debugging Windows and Variousinfo You will be able to understand the use of this buttons by rigorous practise of debuggingvarious projects

Figure 4 Debugger Toolbar

4 Compiler tool barCompiler tool bar is shown in figure 5 and is used in buildingcompilingrunning the currentse-lected project The buttons in Compiler toolbar are (from left to right)

Figure 5 Compiler Toolbar

(a) Build For building the currentselected project

(b) Run For running the currentselected project

(c) Build and run For building and running the currentselected project

(d) Rebuild For rebuilding the currentselected project

(e) Abort For aborting the build process for the currentselected project

(f) Build target For defining the type of build target for currentselected project either debugor release

5 ManagerManager is shown in figure 6 It is labelled as Management This window provides the list of allthe open projects and files for easy access to any required file of any project

Figure 6 Manager

6 EditorEditor is shown in figure 7 Here all the coding work will take place It is provided in tabbed

3

fashion to work with many files at once When no project is open the start page or home page isdisplayed in editor The links given in start page is divided into two parts and explained below

Figure 7 Editor StartHome Page

7 Figure 8 is short-cut on Starting page of IDE for creating a new project and opening an alreadycreated project It also contains link for CodeBlock forum where many useful resources can befound along with other useful discussions The link points to url httpforumscodeblocksorgThe second and third link points to BerLiOS Developer Site aims at enriching the Open Sourcecommunity by providing a centralized place for Open Source Developers to control and manageOpen Source Software Development

Figure 8 Shortcut to Create New Project or Open Existing Project

8 Figure 9 is short-cut to list of projects and files already opened in the IDE It is link to few projectsand files from history of IDE

4

Figure 9 Shortcut to History of Projects Opened Using CodeBlocks

9 LogsLog window is shown in figure 6 It is labelled as lsquoLogs amp othersrsquo This window acts as log forvarious actions performed in IDE All logs related to various activities can be checked at appropriatewindows

Figure 10 Logs

5

3 Working with CodeBlock on Windows

In this section we discuss writing and building of three projects First project (hello worldc) is a simpleprogram which displays hello world on output The second project (linec) uses graphicsh header fileand displays a line The third project (3polycpp) uses simplecpp package and draws three polygons onoutput For Windows (Windows 7) we will be using lsquoCodeBlocks-EPrsquo CodeBlocks-EP comeswith integrated WinBGIm (stands for Windows Borland Graphics Interface) In Windows WinBGIm isrequired to run the programs with graphicsh header file When CodeBlocks-EP is run for first time a lsquofileassociation windowrsquo is displayed as shown in figure 11 Select 3rd option ldquoYes associate CodeBlockswith cc++ file typesrdquo or 4th option ldquoYes associate CodeBlocks with every supported type(includingproject files from other IDEs)rdquo and click lsquoOKrsquo

Figure 11 File association window

31 Installation of CodeBlock

CodeBlock used for windows is CodeBlocks-EP (stands for CodeBlocks - EDU Portable) WinBGIm(Borland Graphics Interface) required to run programs with graphicsh header is already integrated inCodeBlocks-EP Download Codeblocks-EP from httpcodeblockscodecutterorg The installationsteps are as given below

1 Download CodeBlock-EP installer from the link given above and browse to the appropriate di-rectory where the installer is downloaded Click the exe file downloaded and window as shown infigure 12 will pop up Click lsquoRunrsquo

Figure 12 Click on ldquoRunrdquo

6

2 A new window appears as shown in figure 13 Click lsquoNextrsquo

Figure 13 Welcome to the CodeBlocks-EP Setup Wizard screen

3 The third windows that appears is of license agreement as shown in figure 14 Select ldquoI accept theagreementrdquo and click lsquoNextrsquo

Figure 14 License Agreement

7

4 The next window displays some important information (shown in figure 15) regarding CodeBlock-EP Kindly go through information and click on ldquoNextrdquo

Figure 15 Information window

5 Next window asks for location where the CodeBlock-EP will be installed The default location willbe CProgram FilesCodeBlocks-EP Figure 16 shows the location provided for CodeBlocks-EP installation Provide appropriate location and click on ldquoNextrdquo

Figure 16 Providing location for CodeBlocks-EP installation

8

Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar Click onldquoNextrdquo

Figure 17 Providing folder for CodeBLocks-EP shortcuts

Select the checkbox lsquoCreate a desktop iconrsquo as shown in Figure 18 Click lsquoNextrsquo

Figure 18 Creating desktop shortcut for CodeBlocks-EP

9

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

(k) Replace To replace required text in the file in active editor by some alternate text

3 Debugger tool barDebugger tool bar is shown in figure 4 Debugger tool bar is used to debug the currentselectedproject The buttons in debugger toolbar are (from left to right) DebugContinue Run to cursorNext lineNext instruction Step into Step out Stop debugger Debugging Windows and Variousinfo You will be able to understand the use of this buttons by rigorous practise of debuggingvarious projects

Figure 4 Debugger Toolbar

4 Compiler tool barCompiler tool bar is shown in figure 5 and is used in buildingcompilingrunning the currentse-lected project The buttons in Compiler toolbar are (from left to right)

Figure 5 Compiler Toolbar

(a) Build For building the currentselected project

(b) Run For running the currentselected project

(c) Build and run For building and running the currentselected project

(d) Rebuild For rebuilding the currentselected project

(e) Abort For aborting the build process for the currentselected project

(f) Build target For defining the type of build target for currentselected project either debugor release

5 ManagerManager is shown in figure 6 It is labelled as Management This window provides the list of allthe open projects and files for easy access to any required file of any project

Figure 6 Manager

6 EditorEditor is shown in figure 7 Here all the coding work will take place It is provided in tabbed

3

fashion to work with many files at once When no project is open the start page or home page isdisplayed in editor The links given in start page is divided into two parts and explained below

Figure 7 Editor StartHome Page

7 Figure 8 is short-cut on Starting page of IDE for creating a new project and opening an alreadycreated project It also contains link for CodeBlock forum where many useful resources can befound along with other useful discussions The link points to url httpforumscodeblocksorgThe second and third link points to BerLiOS Developer Site aims at enriching the Open Sourcecommunity by providing a centralized place for Open Source Developers to control and manageOpen Source Software Development

Figure 8 Shortcut to Create New Project or Open Existing Project

8 Figure 9 is short-cut to list of projects and files already opened in the IDE It is link to few projectsand files from history of IDE

4

Figure 9 Shortcut to History of Projects Opened Using CodeBlocks

9 LogsLog window is shown in figure 6 It is labelled as lsquoLogs amp othersrsquo This window acts as log forvarious actions performed in IDE All logs related to various activities can be checked at appropriatewindows

Figure 10 Logs

5

3 Working with CodeBlock on Windows

In this section we discuss writing and building of three projects First project (hello worldc) is a simpleprogram which displays hello world on output The second project (linec) uses graphicsh header fileand displays a line The third project (3polycpp) uses simplecpp package and draws three polygons onoutput For Windows (Windows 7) we will be using lsquoCodeBlocks-EPrsquo CodeBlocks-EP comeswith integrated WinBGIm (stands for Windows Borland Graphics Interface) In Windows WinBGIm isrequired to run the programs with graphicsh header file When CodeBlocks-EP is run for first time a lsquofileassociation windowrsquo is displayed as shown in figure 11 Select 3rd option ldquoYes associate CodeBlockswith cc++ file typesrdquo or 4th option ldquoYes associate CodeBlocks with every supported type(includingproject files from other IDEs)rdquo and click lsquoOKrsquo

Figure 11 File association window

31 Installation of CodeBlock

CodeBlock used for windows is CodeBlocks-EP (stands for CodeBlocks - EDU Portable) WinBGIm(Borland Graphics Interface) required to run programs with graphicsh header is already integrated inCodeBlocks-EP Download Codeblocks-EP from httpcodeblockscodecutterorg The installationsteps are as given below

1 Download CodeBlock-EP installer from the link given above and browse to the appropriate di-rectory where the installer is downloaded Click the exe file downloaded and window as shown infigure 12 will pop up Click lsquoRunrsquo

Figure 12 Click on ldquoRunrdquo

6

2 A new window appears as shown in figure 13 Click lsquoNextrsquo

Figure 13 Welcome to the CodeBlocks-EP Setup Wizard screen

3 The third windows that appears is of license agreement as shown in figure 14 Select ldquoI accept theagreementrdquo and click lsquoNextrsquo

Figure 14 License Agreement

7

4 The next window displays some important information (shown in figure 15) regarding CodeBlock-EP Kindly go through information and click on ldquoNextrdquo

Figure 15 Information window

5 Next window asks for location where the CodeBlock-EP will be installed The default location willbe CProgram FilesCodeBlocks-EP Figure 16 shows the location provided for CodeBlocks-EP installation Provide appropriate location and click on ldquoNextrdquo

Figure 16 Providing location for CodeBlocks-EP installation

8

Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar Click onldquoNextrdquo

Figure 17 Providing folder for CodeBLocks-EP shortcuts

Select the checkbox lsquoCreate a desktop iconrsquo as shown in Figure 18 Click lsquoNextrsquo

Figure 18 Creating desktop shortcut for CodeBlocks-EP

9

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

fashion to work with many files at once When no project is open the start page or home page isdisplayed in editor The links given in start page is divided into two parts and explained below

Figure 7 Editor StartHome Page

7 Figure 8 is short-cut on Starting page of IDE for creating a new project and opening an alreadycreated project It also contains link for CodeBlock forum where many useful resources can befound along with other useful discussions The link points to url httpforumscodeblocksorgThe second and third link points to BerLiOS Developer Site aims at enriching the Open Sourcecommunity by providing a centralized place for Open Source Developers to control and manageOpen Source Software Development

Figure 8 Shortcut to Create New Project or Open Existing Project

8 Figure 9 is short-cut to list of projects and files already opened in the IDE It is link to few projectsand files from history of IDE

4

Figure 9 Shortcut to History of Projects Opened Using CodeBlocks

9 LogsLog window is shown in figure 6 It is labelled as lsquoLogs amp othersrsquo This window acts as log forvarious actions performed in IDE All logs related to various activities can be checked at appropriatewindows

Figure 10 Logs

5

3 Working with CodeBlock on Windows

In this section we discuss writing and building of three projects First project (hello worldc) is a simpleprogram which displays hello world on output The second project (linec) uses graphicsh header fileand displays a line The third project (3polycpp) uses simplecpp package and draws three polygons onoutput For Windows (Windows 7) we will be using lsquoCodeBlocks-EPrsquo CodeBlocks-EP comeswith integrated WinBGIm (stands for Windows Borland Graphics Interface) In Windows WinBGIm isrequired to run the programs with graphicsh header file When CodeBlocks-EP is run for first time a lsquofileassociation windowrsquo is displayed as shown in figure 11 Select 3rd option ldquoYes associate CodeBlockswith cc++ file typesrdquo or 4th option ldquoYes associate CodeBlocks with every supported type(includingproject files from other IDEs)rdquo and click lsquoOKrsquo

Figure 11 File association window

31 Installation of CodeBlock

CodeBlock used for windows is CodeBlocks-EP (stands for CodeBlocks - EDU Portable) WinBGIm(Borland Graphics Interface) required to run programs with graphicsh header is already integrated inCodeBlocks-EP Download Codeblocks-EP from httpcodeblockscodecutterorg The installationsteps are as given below

1 Download CodeBlock-EP installer from the link given above and browse to the appropriate di-rectory where the installer is downloaded Click the exe file downloaded and window as shown infigure 12 will pop up Click lsquoRunrsquo

Figure 12 Click on ldquoRunrdquo

6

2 A new window appears as shown in figure 13 Click lsquoNextrsquo

Figure 13 Welcome to the CodeBlocks-EP Setup Wizard screen

3 The third windows that appears is of license agreement as shown in figure 14 Select ldquoI accept theagreementrdquo and click lsquoNextrsquo

Figure 14 License Agreement

7

4 The next window displays some important information (shown in figure 15) regarding CodeBlock-EP Kindly go through information and click on ldquoNextrdquo

Figure 15 Information window

5 Next window asks for location where the CodeBlock-EP will be installed The default location willbe CProgram FilesCodeBlocks-EP Figure 16 shows the location provided for CodeBlocks-EP installation Provide appropriate location and click on ldquoNextrdquo

Figure 16 Providing location for CodeBlocks-EP installation

8

Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar Click onldquoNextrdquo

Figure 17 Providing folder for CodeBLocks-EP shortcuts

Select the checkbox lsquoCreate a desktop iconrsquo as shown in Figure 18 Click lsquoNextrsquo

Figure 18 Creating desktop shortcut for CodeBlocks-EP

9

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

Figure 9 Shortcut to History of Projects Opened Using CodeBlocks

9 LogsLog window is shown in figure 6 It is labelled as lsquoLogs amp othersrsquo This window acts as log forvarious actions performed in IDE All logs related to various activities can be checked at appropriatewindows

Figure 10 Logs

5

3 Working with CodeBlock on Windows

In this section we discuss writing and building of three projects First project (hello worldc) is a simpleprogram which displays hello world on output The second project (linec) uses graphicsh header fileand displays a line The third project (3polycpp) uses simplecpp package and draws three polygons onoutput For Windows (Windows 7) we will be using lsquoCodeBlocks-EPrsquo CodeBlocks-EP comeswith integrated WinBGIm (stands for Windows Borland Graphics Interface) In Windows WinBGIm isrequired to run the programs with graphicsh header file When CodeBlocks-EP is run for first time a lsquofileassociation windowrsquo is displayed as shown in figure 11 Select 3rd option ldquoYes associate CodeBlockswith cc++ file typesrdquo or 4th option ldquoYes associate CodeBlocks with every supported type(includingproject files from other IDEs)rdquo and click lsquoOKrsquo

Figure 11 File association window

31 Installation of CodeBlock

CodeBlock used for windows is CodeBlocks-EP (stands for CodeBlocks - EDU Portable) WinBGIm(Borland Graphics Interface) required to run programs with graphicsh header is already integrated inCodeBlocks-EP Download Codeblocks-EP from httpcodeblockscodecutterorg The installationsteps are as given below

1 Download CodeBlock-EP installer from the link given above and browse to the appropriate di-rectory where the installer is downloaded Click the exe file downloaded and window as shown infigure 12 will pop up Click lsquoRunrsquo

Figure 12 Click on ldquoRunrdquo

6

2 A new window appears as shown in figure 13 Click lsquoNextrsquo

Figure 13 Welcome to the CodeBlocks-EP Setup Wizard screen

3 The third windows that appears is of license agreement as shown in figure 14 Select ldquoI accept theagreementrdquo and click lsquoNextrsquo

Figure 14 License Agreement

7

4 The next window displays some important information (shown in figure 15) regarding CodeBlock-EP Kindly go through information and click on ldquoNextrdquo

Figure 15 Information window

5 Next window asks for location where the CodeBlock-EP will be installed The default location willbe CProgram FilesCodeBlocks-EP Figure 16 shows the location provided for CodeBlocks-EP installation Provide appropriate location and click on ldquoNextrdquo

Figure 16 Providing location for CodeBlocks-EP installation

8

Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar Click onldquoNextrdquo

Figure 17 Providing folder for CodeBLocks-EP shortcuts

Select the checkbox lsquoCreate a desktop iconrsquo as shown in Figure 18 Click lsquoNextrsquo

Figure 18 Creating desktop shortcut for CodeBlocks-EP

9

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

3 Working with CodeBlock on Windows

In this section we discuss writing and building of three projects First project (hello worldc) is a simpleprogram which displays hello world on output The second project (linec) uses graphicsh header fileand displays a line The third project (3polycpp) uses simplecpp package and draws three polygons onoutput For Windows (Windows 7) we will be using lsquoCodeBlocks-EPrsquo CodeBlocks-EP comeswith integrated WinBGIm (stands for Windows Borland Graphics Interface) In Windows WinBGIm isrequired to run the programs with graphicsh header file When CodeBlocks-EP is run for first time a lsquofileassociation windowrsquo is displayed as shown in figure 11 Select 3rd option ldquoYes associate CodeBlockswith cc++ file typesrdquo or 4th option ldquoYes associate CodeBlocks with every supported type(includingproject files from other IDEs)rdquo and click lsquoOKrsquo

Figure 11 File association window

31 Installation of CodeBlock

CodeBlock used for windows is CodeBlocks-EP (stands for CodeBlocks - EDU Portable) WinBGIm(Borland Graphics Interface) required to run programs with graphicsh header is already integrated inCodeBlocks-EP Download Codeblocks-EP from httpcodeblockscodecutterorg The installationsteps are as given below

1 Download CodeBlock-EP installer from the link given above and browse to the appropriate di-rectory where the installer is downloaded Click the exe file downloaded and window as shown infigure 12 will pop up Click lsquoRunrsquo

Figure 12 Click on ldquoRunrdquo

6

2 A new window appears as shown in figure 13 Click lsquoNextrsquo

Figure 13 Welcome to the CodeBlocks-EP Setup Wizard screen

3 The third windows that appears is of license agreement as shown in figure 14 Select ldquoI accept theagreementrdquo and click lsquoNextrsquo

Figure 14 License Agreement

7

4 The next window displays some important information (shown in figure 15) regarding CodeBlock-EP Kindly go through information and click on ldquoNextrdquo

Figure 15 Information window

5 Next window asks for location where the CodeBlock-EP will be installed The default location willbe CProgram FilesCodeBlocks-EP Figure 16 shows the location provided for CodeBlocks-EP installation Provide appropriate location and click on ldquoNextrdquo

Figure 16 Providing location for CodeBlocks-EP installation

8

Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar Click onldquoNextrdquo

Figure 17 Providing folder for CodeBLocks-EP shortcuts

Select the checkbox lsquoCreate a desktop iconrsquo as shown in Figure 18 Click lsquoNextrsquo

Figure 18 Creating desktop shortcut for CodeBlocks-EP

9

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

2 A new window appears as shown in figure 13 Click lsquoNextrsquo

Figure 13 Welcome to the CodeBlocks-EP Setup Wizard screen

3 The third windows that appears is of license agreement as shown in figure 14 Select ldquoI accept theagreementrdquo and click lsquoNextrsquo

Figure 14 License Agreement

7

4 The next window displays some important information (shown in figure 15) regarding CodeBlock-EP Kindly go through information and click on ldquoNextrdquo

Figure 15 Information window

5 Next window asks for location where the CodeBlock-EP will be installed The default location willbe CProgram FilesCodeBlocks-EP Figure 16 shows the location provided for CodeBlocks-EP installation Provide appropriate location and click on ldquoNextrdquo

Figure 16 Providing location for CodeBlocks-EP installation

8

Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar Click onldquoNextrdquo

Figure 17 Providing folder for CodeBLocks-EP shortcuts

Select the checkbox lsquoCreate a desktop iconrsquo as shown in Figure 18 Click lsquoNextrsquo

Figure 18 Creating desktop shortcut for CodeBlocks-EP

9

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

4 The next window displays some important information (shown in figure 15) regarding CodeBlock-EP Kindly go through information and click on ldquoNextrdquo

Figure 15 Information window

5 Next window asks for location where the CodeBlock-EP will be installed The default location willbe CProgram FilesCodeBlocks-EP Figure 16 shows the location provided for CodeBlocks-EP installation Provide appropriate location and click on ldquoNextrdquo

Figure 16 Providing location for CodeBlocks-EP installation

8

Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar Click onldquoNextrdquo

Figure 17 Providing folder for CodeBLocks-EP shortcuts

Select the checkbox lsquoCreate a desktop iconrsquo as shown in Figure 18 Click lsquoNextrsquo

Figure 18 Creating desktop shortcut for CodeBlocks-EP

9

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar Click onldquoNextrdquo

Figure 17 Providing folder for CodeBLocks-EP shortcuts

Select the checkbox lsquoCreate a desktop iconrsquo as shown in Figure 18 Click lsquoNextrsquo

Figure 18 Creating desktop shortcut for CodeBlocks-EP

9

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

6 A new window displays stating that it is ready to install which is shown in Figure 19 Click lsquoInstallrsquoto proceed with installation

Figure 19 Installing CodeBlocks-EP

Figure 20 shows installation progress with progress bar

Figure 20 Progress bar to show progress of installation

10

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

7 When the installation in complete a window is displayed shown in figure 21 If you want to launchthe CodeBlock select ldquoLaunch CodeBlocks-EPrdquo and click lsquoFinishrsquo

Figure 21 Completing the installation process

8 CodeBlocks IDE opens as shown in figure 22 Alternatively CodeBlocks-EP can be launched bydouble clicking the desktop icon created or clicking on itrsquos shortcut icon in Start Menu Bar

Figure 22 CodeBlock IDE in Windows 7

11

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

32 Installation of Simplecpp

The steps to be followed to install simplecpp are as listed below Download the targz file from http

wwwitiitbacinfrgwikiimagesff3Simplecpp-Windowstargz Untar the file and go intothe simplecpprsquos folder The steps have been tested on Windows 7

1 Close all the running instance of Codeblock-EP

2 Double click on exe simplecpp file A window is displayed as shown in figure 23 Click lsquoRunrsquo

Figure 23 Installation of simplecpp on windows

3 A new window opens which is labelled lsquoSetup - Simplecpprsquo as shown in figure 24 Click on lsquoNextrsquo

Figure 24 Setup - Simplecpp

12

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

4 A new window is displayed to select path of installation as shown in figure 25 By default it islsquoCProgramFilesCodeblocks-EPrsquo If you want to change the installation path click rsquoBrowsersquonavigate to the directory and click rsquoOkrsquo else leave it unchanged Click lsquoNextrsquo

Figure 25 Selecting CodeBlocks-EPrsquos installation folder

5 A new window stating that simplecpp is ready to install is displayed This is shown in figure 26Click lsquoInstallrsquo

Figure 26 Install

13

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

6 Finally click lsquoFinishrsquo to complete the installation as shown in figure 27

Figure 27 Finish Simplecpp installation

33 Writing a new CC++ Program

This section is divided into writing non-graphic program writing graphic program using graphicshheader file and writing graphic program using simplecpp package

331 Non-Graphic Project

1 Click on New file button The lsquoNew from templatersquo window as shown in figure 28 opens Fornon-graphics projects select lsquoConsole applicationrsquo When the type of project is selected the Gobutton gets highlighted (top right corner) Click Go

Figure 28 New form template

14

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

2 When Go button is clicked a new window opens as shown in figure 29 Select checkbox ldquoSkip thispage next timerdquo so that the page is not displayed again Click lsquoNextrsquo

Figure 29 New console application wizard

3 Next window enables user to select the language to be used for project as shown in Figure 30Select CC++ Here lsquoCrsquo is selected for helloworld project Click lsquoNextrsquo

Figure 30 Selecting language for the project

15

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

4 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project in This is Shown in figure 31 After filling in the details click on Next

Figure 31 Providing title and folder for the project

5 Next window is used to select the compiler as shown in figure 32 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 32 Selecting compiler for the project

16

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

6 The project node opens in manager window as shown in figure 33 The project node is empty andwe have to add files to the project

Figure 33 Project node with no files

7 To add files to the project select project node and click on Filein menu bar then click on lsquoFilersquoin options in rsquoNewrsquo The process is shown in figure 34

Figure 34 Adding file to the project

17

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

8 New from template opens as shown in figure 35 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 35 Selecting type of file to be added in the project

9 A new window is displayed as shown in figure 36 Select the checkbox lsquoSkip this page next timersquoso that it is not displayed again

Figure 36 Select checkbox to skip this window next time

18

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

10 Select the preferred language as shown in figure 37 We have selected lsquoCrsquo for our helloworld example

Figure 37 Select the language of the file added

11 Figure 38 shows the window that opens to add the file click on lsquorsquo beside lsquoFilename with fullpathrsquo

Figure 38 Details of file to be added

19

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

A window as shown in figure 39 opens Select the folder of the project and enter file name to beadded Click on lsquoSaversquo

Figure 39 Selecting the location and file name to be added

When lsquoSaversquo button is clicked the window in figure 38 opens again with full path and name of thefile Select Debug and Release Shown in figure 40 Click on Finish

Figure 40 Finalize details of file to be added

20

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

12 Management window now shows project node which can be expanded Click on project node anddouble click on lsquohellocrsquo to open the file in editor shown in figure 41 and figure 42

Figure 41 Project node with lsquo+rsquo sign indicating it can be expanded

Figure 42 Project node expanded

13 When the helloc file opens in editor user can start coding Code is shown in figure 43

Figure 43 Writing code in editor

21

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

332 Graphic Project using graphicsh

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects select lsquoWinBGIm projectrsquo Go button gets highlighted (top right corner) Clickon Go

Figure 44 New form template

2 When Go button is clicked a new window opens as shown in Figure 45 Select checkbox ldquoSkip thispage next timerdquo so every time new project is created this window should not come Click on NextIf this step has been performed earlier this window will not be displayed

Figure 45 New console application wizard

3 Next window enables user to select the language to be used for project as shown in figure 46 For

22

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

the example hello world used in this manual select lsquoCrsquo and click on Next

Figure 46 Selecting language for the project

4 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 47 Select lsquoGraphics onlyrsquo and click on Next

Figure 47 WinBGIm project

23

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

5 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 48 After filling in the details click on Next

Figure 48 Providing title and folder for the project

6 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 49 Selecting compiler for the project

24

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

7 The project node opens in manager window The project node is empty and we have to add files tothe project To add files to the project select project node and click on File in menu bar then clickon lsquoFilersquo in options in rsquoNewrsquo New from template opens as shown in figure 35 For our exampleselect lsquoCC++ sourcersquo and click on Go A new window pops out which have a checkbox lsquoSkip thispage next timersquo Select the checkbox so this window should not open every time a new file is addedto the project Select the preferred language For our example select lsquoCrsquo A new window openswhich allows user to add the files to the project Click on lsquorsquo beside lsquoFilename with full pathrsquoThis is shown in Figure 38 A window as shown in figure 39 opens Select the folder of the projectand enter file name to be added Click on lsquoSaversquo (see steps 6-11 of section 5211) Select Debugand Release Shown in figure 50 Click on Finish

Figure 50 Finalize details of file to be added (for line project)

8 Management window now shows project node which can be expanded (figure 51)

Figure 51 Project node with lsquo+rsquo sign indicating it can be expanded

25

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

9 Click on project node and double click on lsquolinecrsquo to open the file in editor When the linec fileopens in editor user can start coding Code is shown in figure 52

Figure 52 Writing program in editor (line project)

333 Graphic Project using simplecpp

1 Click on New file button The lsquoNew form templatersquo window as shown in figure 28 opens Forgraphics projects using simplecpp select lsquoSimplecpp projectrsquo Go button gets highlighted (topright corner) Click on Go

Figure 53 New from template

26

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

2 Next window asks the user to select type of project The options are lsquoAdd Consolersquo and lsquoGraphicsonlyrsquo as shown in figure 54 Select lsquoGraphics onlyrsquo and click on Next

Figure 54 Simplecpp project

3 Next windows enables user to provide title for the project and the folder where user wishes tocreate the project This is Shown in figure 55 After filling in the details click on Next

Figure 55 Providing title and folder for the project

27

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

4 Next window is used to select the compiler as shown in figure 49 By default lsquoGNU GCC Compilerrsquois selected Click on Finish

Figure 56 Selecting compiler for the project

5 The project node opens in manager window The project node is empty as shown in figure 57 Wehave to add files to the project

Figure 57 Empty project node in Management window

28

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

6 To add files to the project select project node and click on File in menu bar then click on lsquoFilersquoin options in rsquoNewrsquo Shown in figure 58

Figure 58 Adding files to empty project node

7 New from template opens as shown in figure 59 For our example select lsquoCC++ sourcersquo and clickon Go

Figure 59 Selecting cc++ source for project

29

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

8 Select the preferred language For our example select lsquoC++rsquo (figure 60)

Figure 60 Selecting language for the file to be added

A new window opens which allows user to add the files to the project Click on lsquorsquo beside lsquoFilenamewith full pathrsquo This is shown in Figure 38 A window as shown in figure 61 opens Select thefolder of the project and enter file name to be added Click on lsquoSaversquo

Figure 61 Giving location and name of the file to be added

30

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

In next window select Debug and Release Shown in figure 62 Click on Finish

Figure 62 Finalize details of file to be added

9 Management window now shows project node which can be expanded (figure 63)

Figure 63 Project node with lsquo+rsquo sign indicating it can be expanded

31

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

10 Click on project node and double click on lsquo3polycpprsquo to open the file in editor When the 3polycppfile opens in editor (figure 64) user can start coding Code is shown in figure 65

Figure 64 opening file in editor

Figure 65 coding

32

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

34 Building the Project

The process to build the graphics and non-graphics project is same just Click on lsquoBuildrsquo and then lsquoRunrsquo(or directly on lsquoBuild and runrsquo) The output for the program used is shown in figure 66 for hello worldproject figure 67 for line project and figure 68 for 3poly project

Figure 66 Output of hello world project

Figure 67 Output of line project

Figure 68 Output of 3poly project

33

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

35 Opening existing programproject

Click on Open button 69 Browse to desired directory and open the file with cbp extension as shown infigure 70

Figure 69 Selecting Open under file in Menu Bar

Figure 70 Select file with cbp extension to open an existing project

34

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

4 Working with CodeBlock on Ubuntu

In this section we discuss writing and building three projects First project (hello worldc) is simpleprogram which displays hello world on output The other project (linec) uses graphicsh header file anddisplays a line graphicsh is not supported by gcc which is the default CC++ compiler on UbuntuThe third project (3polycpp) uses simplecpp package and draws three polygons on output We have toinstall some packages include few libgraph libraries during building the project with graphich headerfile

41 Installation of CodeBlocks

Pre-requisite for installing CodeBlock is lsquolibwxgtkrsquo which is available in ubuntu software center Thispackage will be already installed in your system3 It is also advised to install lsquobuild-essentialrsquo packageand update repository list In case the libwxgtk is not installed it can be installed from command lineusing command given in listing 1 [3] CodeBlock is available in Ubuntursquos repository It can be installedusing Ubuntu Software Center or it can also be installed using command line as given in listing 2

1 $ sudo aptminusget i n s t a l l l ibwxgtk2 8minus02 $ sudo aptminusget i n s t a l l bui ldminuse s s e n t i a l3 $ sudo aptminusget update

Listing 1 Installing libwxgtk28-0 using command line

1 $ sudo aptminusget i n s t a l l codeb locks

Listing 2 Installing CodeBlocks using command line

Figure 71 CodeBlock in Ubuntu Software Center

Figure 72 Installing CodeBlock using command line

3Check for the libwxgtk version available for your Ubuntu minimum required version for CodeBlock to run is 20version available on Ubuntu 1204 is 28

35

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

Figure 71 shows CodeBlock along with itrsquos logo in Ubuntu Software Center while figure 72 showsinstallation of CodeBlock using command line In figure 72 four underlined lines are

line 1 Command to install the CodeBlock

line 2 Packages installed along with CodeBlock

line 3 Packages suggested along with CodeBlock installation libwxgtk284 package as mentioned aboveis already installed in your system libwxgtk28-dev package is not required

line 4 Final list of packages that will be installed in your system

When command line prompts for [Yn] enter lsquoyrsquo and press enter When CodeBlock is run for first timeIt asks for default compiler Select the appropriate compiler to proceed further We have used lsquoGNUGCC Compilerrsquo

42 Installation of packages for graphicsh header file

GCC compiler does not support graphicsh conioh windowsh and few other header files that workson Turbo C or Borland C graphicsh header files enables programmer to write simple cc++ graphicsprograms In Ubuntu gcc is default cc++ compiler thus we have to make some settings for gcc tosupport graphics[4] We will start with installing some packages from command line as given in listing 3

1 $ sudo aptminusget i n s t a l l l i b s d lminusimage1 2 l i b s d lminusimage1 2minusdev gu i l e minus18 gu i l e minus18minusdevl i b s d l 1 2 debian l i b a r t minus20minusdev l i b a u d i o f i l e minusdev l ibe sd0minusdev l i b d i r e c t f b minusdevl i b d i r e c t f b minusext ra l i b f r e e t yp e 6minusdev l ibxextminusdev x11protominusxextminusdev l i b f r e e t y p e 6l i baa1 l ibaa1minusdev l i b s l ang2minusdev l ibasound2 l ibasound2minusdev

Listing 3 Installing required packages to support graphicsh

After the above mentioned packages are installed download the libgraph package (download linkgiven in footnote5 ) and untar it in home directory For this untarring tool must be installed on systemOpen the command line and follow the instructions given in listing 4

1 $ cd l ibgraph minus10 22 $ c on f i gu r e3 $ sudo make4 $ sudo make i n s t a l l5 $ sudo cp usr l o c a l l i b l ibg raph lowast usr l i b

Listing 4 Installing libgraph package using command line

43 Installation of Simplecpp

Download the simplecpprsquos tar package and untar it The tar file can be downloaded from the link givenin footnote6 Change to the simplecpp directory and run the command lsquosh configureshrsquo Shown infigure 73

1 $ cd DIRECTORY WHERE Simplecpp tar IS DOWNLOADED2 $ tar minusxvf Simplecpp ta r3 $ cd simplecpp 4 $ sh con f i gu r e sh

Listing 5 Installing simplecpp package using command line

4Details about above mentioned packages can be found at httppackagesubuntucompreciseallpackages5httpdownloadsavannahgnuorgreleaseslibgraphlibgraph-102targz6httpwwwitiitbacinfrgwikiimages445Simplecpptar

36

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

Figure 73 Installing simplecpp

The last line in installation process mentions To compile use homesandeepProjectsreportscode-blockssimplecpps++ filenamecpp The path to simplecpps++ will vary from user to user as peruserrsquos machine this path is location of simplecpps++ on the machine Shown in figure 74

Figure 74 location of simplecpps++

For the project using simplecpp package some setting has to be changed The steps to make therequired changes are as given below

1 Open CodeBlocks and click on lsquoSettingrsquo and select lsquoComplier and Debuggerrsquo A window labelledCompiler and debugger settings will open as shown in Figure 76 By default the selected compileris lsquoGNU GCC Compilerrsquo Click lsquoCopyrsquo highlighted with red box in figure 76 A window as shownin figure 75 will open Write lsquosimplecpprsquo and click lsquoOkrsquo

Figure 75 Copying the compiler

37

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

2 A message stating rsquochange the appropriate setting in Toolchain executablersquo is displayed which isshown in figure 76

3 Click on lsquoToolchain executablesrsquo tab highlighted with red box in figure 76

Figure 76 Compiler and debugger settings

38

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

4 Change the compiler path of CodeBlocks to that of simplecpp The steps are given below

5 Click all lsquorsquo buttons highlighted with red box in figure 77) on by one Change all the settingsas shown in figure When lsquorsquo is clicked browse to the lsquosimplecpprsquo directory This is shown infigure 78 lsquos++rsquo and lsquomakes++rsquo are available in lsquosimplecpprsquo folder lsquolibspritearsquo is available inlsquosimplecpplibrsquo folder

Figure 77 Changes to be made in Toolchain Executables

6 To summarize the list of all the fields that need to be changed is given below

(a) Compilerrsquos installation directory simplecpp

(b) C compiler simplecpps++

(c) C++ compiler simplecpps++

(d) Linker for Dynamic libs simplecpps++

(e) Linker for static libs simplecpps++libspritea

(f) Make program simplecppmakes++

7 When all the required fields are changed click on lsquoAdditional Pathsrsquo shown in red block in figure 77

39

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

Figure 78 Simplecpprsquos directory

8 In Additional Paths click on Add shown in red block in figure 79 Browse to simplecpp directoryand click on Ok User will return on Compiler and debugger setting window Click Ok again toexit settings and return to editor

Figure 79 Additional Paths settings

40

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

44 Writing a new cc++ program

1 Click on New file button The lsquoNew from templatersquo window opens as shown in figure 80 Selectthe type of project you want to program in When the type of project is selected the Go buttongets highlighted (top right corner) Select lsquoConsole applicationrsquo and click on lsquoGorsquo

Figure 80 Starting a new project

2 When Go button is clicked a new window opens as shown in figure 81 This window enables theuser to select the required language to proceed Select the language and click on next

Figure 81 Selecting the language for project

41

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

3 The subsequent windows enable the user to provide title for the project and the folder where userwishes to create the project in This is shown in figure 82 After filling in the details click lsquoNextrsquo

Figure 82 Title for Project

4 Next window is to select the compiler By default lsquoGNU GCC Compilerrsquo is selected In this windowthe user can change the compiler to be used as per the use and requirementsNon-graphic and Programs including graphicsh header file Select lsquoGNU GCC Compilerrsquo(figure 83)Simplecpp programs Select lsquoSimplecpprsquo (figure 84) Click on Finish

Figure 83 Selecting Compiler to Compile the Program

42

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

Figure 84 Selecting simplecpp for projects including simplecpp

5 Now the project node opens in manager window as shown in figure 85 Project node can beexpanded to see the mainc file

Figure 85 Project Node when Expanded

43

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

When mainc file is clicked it opens in editor as shown in figure 86 for hello world project

Figure 86 Project Node when Expanded for helloworldc (with code shown in editor)

6 Code used for graphics program (line) is shown in figure 87

Figure 87 Project node when expanded for linec (with code shown in editor)

44

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

7 Code used for simplecpp program (3poly) is shown in figure 88 Every project involving simplecpphas to include simplecpp package as seen in first line of the code

Figure 88 Project node when expanded for 3polycpp (with code shown in editor)

8 While using CodeBlocks for the first time some extra windows will be displayed In this manualonly the important windows are shown

45 Building the Project

451 Non-Graphics Project

After the code is written project needs to be built Click on lsquobuild and runrsquo from compiler bar Outputis as shown in figure 89

Figure 89 Output for helloworldc

452 Graphics Project using graphicsh

To build a program involving graphicsh it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix C

45

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

Now the project using graphicsh (line) has to be linked with libraries copied in usrlib while installinglibgraph package The steps to link the libraries and build the project is given below

1 Right click on project node in Manager box and select build options A new window lsquoProject buildoptionsrsquo as shown in figure 90 pops up Option to change the compiler selected for the project isalso available in this window

Figure 90 Project build options

2 In lsquoProject build optionsrsquo window click on linker settings tab This tab is shown in figure 91

Figure 91 Linker settings (Add Libraries)

46

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

3 In linker settings tab click on Add button under Link libraries box When Add button is clicked asmall window titled Add library opens as shown in figure 92

Figure 92 Interface for adding libraries

4 Click on dotted button to right of box A new window opens as shown in figure 93This window enables user to browse to appropriate folder and to select required library Browse tothe usrlib directory All the required library files are not visibleSelect all files in dropdown placed at the bottom to enable visibility of all types of filesSelect all the libgraph files except libgraphla file Files to be selected are shown in the figure 93

Figure 93 Fileslibraries to be added for graphic projects

47

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

5 Libraries shown in Ubuntu 1204 32-bit OS are libgrapha libgraphso libgraphso1 libgraphso102libgraphso4 and libgraphso400 In Ubuntu 1204 64-bit OS libraries libgraphso4 and lib-graphso400 are not available Select all the libgraph files except libgraphla

6 After selecting all the required libraries click on Open A new window labelled lsquoQuestionrsquo will openasking lsquoKeep this as relative pathrsquo as shown in figure 94 Click on No

Figure 94 Relative or absolute path for fileslibraries

7 The libraries will be linked using absolute path as shown in figure 95 Click on lsquoOkrsquo

Figure 95 libraries selected

48

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

8 We are now re-directed to linker settings tab The added libraries are shown In Other linkeroptions window write lsquo-lgraphrsquo The final setup is shown in figure 96 with all the required 6libraries and lsquo-lgraphrsquo Click on lsquoOkrsquo to get back to editor Now we are ready to build the projectwith graphicsh header file

Figure 96 Libraries added to project

9 Now click the build and run button from compiler bar and output will be displayed as shown infigure 97

Figure 97 Output for linec

49

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

453 Graphics Project using simplecpp

To build a program involving simplecpp it is recommend to enable full logging in CodeBlock Fulllogging also helps in better debugging Steps to enable full Full logging in CodeBlock is given inappendix CClick the build and run button from compiler bar and output will be displayed as shown in figure 98

Figure 98 Output for 3polycpp

50

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

46 Opening Existing ProgramProject

Click File and select lsquoOpenrsquo Browse to desired directory and select the file with cbp extension as shownin figure 99 and click on Open

Figure 99 Select file with cbp extension to open an existing project

51

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

References

[1] The CodeBlock Team Codeblock homepagehttpwwwcodeblocksorg

[2] The CodeBlock Team Gpl v30 licensehttpwwwcodeblocksorglicense

[3] Installing codeblock on ubuntuhttpwikicodeblocksorgindexphptitle=Installing_CodeBlocks_from_source_on_

Linux

[4] Eternal thinker How to use graphicsh in ubuntuhttpblogeternal-thinkercom201009how-to-use-graphicsh-in-ubuntuhtml

[5] Codeblock faqrsquoshttpwikicodeblocksorgindexphptitle=FAQ

52

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

A Code used for Windows

A1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 6 helloworldc

A2 linec

1 inc ludelts t d i o hgt2 inc ludeltgraph i c s hgt3 i n t main ( )4 5 i n t gd gm gd=DETECT6 in i t g r aph (ampgdampgmNULL) 7 l i n e (50 50 80 80 ) 8 de lay (5000) 9 re turn 0

10

Listing 7 linec

A3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 8 3polycpp

53

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

B Code used for Ubuntu

B1 helloworldc

1 inc lude lts t d i o hgt23 i n t main ( )4 5 p r i n t f (rdquo He l lo world nrdquo) 6 re turn 0 7

Listing 9 helloworldc

B2 linec

1 inc lude lts t d i o hgt2 inc lude ltgraph i c s hgt34 i n t main ( )5 6 i n t gd gm gd=DETECT7 in i t g r aph (ampgdampgmNULL) 8 l i n e (50 50 80 80 ) 9 de lay (5000)

1011 re turn 0 12

Listing 10 linec

B3 3polycpp

1 inc lude ltsimplecppgt23 main program4 in i tCanvas ( ) 5 Turt le t1 t2 t3 67 t2 l e f t (120) 8 t3 l e f t (240) 9

10 repeat (8 ) 11 t1 forward (100) 12 t2 forward (100) 13 t3 forward (100) 1415 t1 l e f t ( 360 08 ) 16 t2 l e f t ( 360 08 ) 17 t3 l e f t ( 360 08 ) 18 19 wait (5 ) 20

Listing 11 3polycpp

54

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock

C Enabling full logging in CodeBlock

Logging can be used extensively for many purposes including debugging and profiling Steps to enablefull logging in CodeBlock [5] are as mentioned below

Settings rarr Compiler and debugger settings rarr Global compiler settings rarr check Selected compiler rarrOther settings rarr Compiler logging rarr Full command line

1 Click on Setting in Menu bar and select Compiler and debugger settings

2 Select Global compiler settings from list on left panel The default compiler selected is shown abovein right panel Here we can change the default compiler

3 Click on right arrow beside tabs to select lsquoOther settingsrsquo

4 The first option is of Compiler logging select lsquoFull command linersquo

55

  • Introduction
    • CodeBlocks
    • Simplecpp
      • CodeBlock IDE
      • Working with CodeBlock on Windows
        • Installation of CodeBlock
        • Installation of Simplecpp
        • Writing a new CC++ Program
          • Non-Graphic Project
          • Graphic Project using graphicsh
          • Graphic Project using simplecpp
            • Building the Project
            • Opening existing programproject
              • Working with CodeBlock on Ubuntu
                • Installation of CodeBlocks
                • Installation of packages for graphicsh header file
                • Installation of Simplecpp
                • Writing a new cc++ program
                • Building the Project
                  • Non-Graphics Project
                  • Graphics Project using graphicsh
                  • Graphics Project using simplecpp
                    • Opening Existing ProgramProject
                      • Code used for Windows
                        • helloworldc
                        • linec
                        • 3polycpp
                          • Code used for Ubuntu
                            • helloworldc
                            • linec
                            • 3polycpp
                              • Enabling full logging in CodeBlock