This document provides instructions for installing and using Code::Blocks IDE and the Simplecpp library on Windows and Ubuntu systems. It explains how to install Code::Blocks, Simplecpp, and additional required packages. It then demonstrates how to create and build C/C++ projects, both graphical and non-graphical, within the Code::Blocks IDE. Code samples for simple programs are provided in the appendices.
This document provides instructions for installing and using Code::Blocks IDE and the Simplecpp library on Windows and Ubuntu systems. It explains how to install Code::Blocks, Simplecpp, and additional required packages. It then demonstrates how to create and build C/C++ projects, both graphical and non-graphical, within the Code::Blocks IDE. Code samples for simple programs are provided in the appendices.
This document provides instructions for installing and using Code::Blocks IDE and the Simplecpp library on Windows and Ubuntu systems. It explains how to install Code::Blocks, Simplecpp, and additional required packages. It then demonstrates how to create and build C/C++ projects, both graphical and non-graphical, within the Code::Blocks IDE. Code samples for simple programs are provided in the appendices.
This document provides instructions for installing and using Code::Blocks IDE and the Simplecpp library on Windows and Ubuntu systems. It explains how to install Code::Blocks, Simplecpp, and additional required packages. It then demonstrates how to create and build C/C++ projects, both graphical and non-graphical, within the Code::Blocks IDE. Code samples for simple programs are provided in the appendices.
Department of Computer Science and Engineering Indian Institute of Technology - Bombay Mumbai - 400076. April 9, 2014 Contents 1 Introduction 1 1.1 Code::Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Simplecpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 Code::Block IDE 1 3 Working with Code::Block on Windows 6 3.1 Installation of Code::Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.2 Installation of Simplecpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.3 Writing a new C/C++ Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.3.1 Non-Graphic Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.3.2 Graphic Project using graphics.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3.3.3 Graphic Project using simplecpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.4 Building the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3.5 Opening existing program/project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 4 Working with Code::Block on Ubuntu 35 4.1 Installation of Code::Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 4.2 Installation of packages for graphics.h header le . . . . . . . . . . . . . . . . . . . . . . . 36 4.3 Installation of Simplecpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.4 Writing a new c/c++ program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.5 Building the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.5.1 Non-Graphics Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.5.2 Graphics Project using graphics.h . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.5.3 Graphics Project using simplecpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 4.6 Opening Existing Program/Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 A Code used for Windows 53 A.1 helloworld.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 A.2 line.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 A.3 3poly.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 B Code used for Ubuntu 54 B.1 helloworld.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 B.2 line.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 B.3 3poly.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 C Enabling full logging in Code::Block 55 i List of Figures 1 Code::Block IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 Menu Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 3 Main Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 4 Debugger Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 5 Compiler Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 6 Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 7 Editor, Start/Home Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 8 Shortcut to Create New Project or Open Existing Project . . . . . . . . . . . . . . . . . . 4 9 Shortcut to History of Projects Opened Using Code::Blocks . . . . . . . . . . . . . . . . . 5 10 Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 11 File association window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 12 Click on Run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 13 Welcome to the CodeBlocks-EP Setup Wizard screen . . . . . . . . . . . . . . . . . . . . . 7 14 License Agreement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 15 Information window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 16 Providing location for CodeBlocks-EP installation . . . . . . . . . . . . . . . . . . . . . . 8 17 Providing folder for CodeBLocks-EP shortcuts . . . . . . . . . . . . . . . . . . . . . . . . 9 18 Creating desktop shortcut for CodeBlocks-EP . . . . . . . . . . . . . . . . . . . . . . . . . 9 19 Installing CodeBlocks-EP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 20 Progress bar to show progress of installation . . . . . . . . . . . . . . . . . . . . . . . . . . 10 21 Completing the installation process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 22 Code::Block IDE in Windows 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 23 Installation of simplecpp on windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 24 Setup - Simplecpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 25 Selecting CodeBlocks-EPs installation folder . . . . . . . . . . . . . . . . . . . . . . . . . 13 26 Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 27 Finish Simplecpp installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 28 New form template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 29 New console application wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 30 Selecting language for the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 31 Providing title and folder for the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 32 Selecting compiler for the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 33 Project node with no les . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 34 Adding le to the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 35 Selecting type of le to be added in the project . . . . . . . . . . . . . . . . . . . . . . . . 18 36 Select checkbox to skip this window next time . . . . . . . . . . . . . . . . . . . . . . . . . 18 37 Select the language of the le added . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 38 Details of le to be added . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 39 Selecting the location and le name to be added . . . . . . . . . . . . . . . . . . . . . . . 20 40 Finalize details of le to be added . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 41 Project node with + sign indicating it can be expanded . . . . . . . . . . . . . . . . . . . 21 42 Project node expanded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 43 Writing code in editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 44 New form template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 45 New console application wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 46 Selecting language for the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 47 WinBGIm project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 48 Providing title and folder for the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 49 Selecting compiler for the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 50 Finalize details of le to be added (for line project) . . . . . . . . . . . . . . . . . . . . . . 25 51 Project node with + sign indicating it can be expanded . . . . . . . . . . . . . . . . . . . 25 52 Writing program in editor (line project) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 53 New from template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 ii 54 Simplecpp project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 55 Providing title and folder for the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 56 Selecting compiler for the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 57 Empty project node in Management window . . . . . . . . . . . . . . . . . . . . . . . . . 28 58 Adding les to empty project node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 59 Selecting c/c++ source for project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 60 Selecting language for the le to be added . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 61 Giving location and name of the le to be added . . . . . . . . . . . . . . . . . . . . . . . 30 62 Finalize details of le to be added . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 63 Project node with + sign indicating it can be expanded . . . . . . . . . . . . . . . . . . . 31 64 opening le in editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 65 coding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 66 Output of hello world project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 67 Output of line project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 68 Output of 3poly project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 69 Selecting Open under le in Menu Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 70 Select le with .cbp extension to open an existing project . . . . . . . . . . . . . . . . . . 34 71 Code::Block in Ubuntu Software Center . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 72 Installing Code::Block using command line . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 73 Installing simplecpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 74 location of simplecpp/s++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 75 Copying the compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 76 Compiler and debugger settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 77 Changes to be made in Toolchain Executables . . . . . . . . . . . . . . . . . . . . . . . . . 39 78 Simplecpps directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 79 Additional Paths settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 80 Starting a new project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 81 Selecting the language for project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 82 Title for Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 83 Selecting Compiler to Compile the Program . . . . . . . . . . . . . . . . . . . . . . . . . . 42 84 Selecting simplecpp for projects including simplecpp . . . . . . . . . . . . . . . . . . . . . 43 85 Project Node when Expanded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 86 Project Node when Expanded for helloworld.c (with code shown in editor) . . . . . . . . . 44 87 Project node when expanded for line.c (with code shown in editor) . . . . . . . . . . . . . 44 88 Project node when expanded for 3poly.cpp (with code shown in editor) . . . . . . . . . . . 45 89 Output for helloworld.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 90 Project build options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 91 Linker settings (Add Libraries) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 92 Interface for adding libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 93 Files/libraries to be added for graphic projects . . . . . . . . . . . . . . . . . . . . . . . . 47 94 Relative or absolute path for les/libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 95 libraries selected . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 96 Libraries added to project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 97 Output for line.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 98 Output for 3poly.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 99 Select le with .cbp extension to open an existing project . . . . . . . . . . . . . . . . . . 51 iii 1 Introduction 1.1 Code::Blocks Code::Blocks is a free C++ IDE built to meet the most demanding needs of its users. [1]. Developed by The Code::Blocks Team, Code::Block is a free, open-source [2] and cross-platform IDE, which supports various free compilers. It is built around plugin framework, which allows functionality of Code::Block to be extended by installing appropriate plugins. Plugins required for compiling and debugging are already provided by default. This manual is prepared after installing and testing Code::Block on Ubuntu 12.04 1 and Windows 7. 2 1.2 Simplecpp Simplecpp is a package used to write and execute turtle based non-graphic/graphic programs. Simplecpp is a package developed by Prof. Abhiram Ranade at IIT Bombay and the book on An Introduction to Programming through C++ 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 with Code::Blocks and the simplecpp programs are tested with Code::Blocks on Windows 7 and Ubuntu 12.04. 2 Code::Block IDE Code::Block IDE is shown in gure 1 (Ubuntu 12.04). The main parts of Code::Block along with gures are discussed below Figure 1: Code::Block IDE 1 Ubuntu 12.04 with intel R Core TM i3-2120 CPU @ 3.30GHzx4 processor 4 GB RAM and 32-bit architecture and 64 bit architecture. 2 Windows 7 with intel R Core TM i3-2120 CPU @ 3.30GHzx4 processor 4 GB RAM and 32-bit architecture. 1 1. Menu bar: Menu bar is shown in gure 2. Menu bar can be toggled using F10. Few important link in menu bar 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 project, save le, save project, save workspace and save everything. It also contains options for closing a single le, closing a project or closing entire workspace. Other options in File are to print, export and quit the Code::Block (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 manager, logs, script console, status bar, full screen. (d) Project: Options related to the project is provided in this link which includes conguring build options along with options for adding les, removing les and autoversioning of project. (e) Build: Options for building the project, compiling a single le, running the project, building and running the project, rebuilding the project and cleaning the project is provided in build. Options for Building, rebuilding and cleaning the entire workspace is also provided along with options to select target (debug/release) 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 is also provided here. (h) Settings: This contains link for various settings, setting related to Environment..., Editor..., Compiler and debugger..., Global Variables... and Scripting.... Script to be executed during Code::Block start-up can also be edited here. (i) Help: It contains information about Code::Block version, tips which can be toggled to be displayed at start-up and information about various plugins. 2. Main tool bar: Main tool bar is shown in gure 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 le open in active editor (active editor means the editor tab in focus). (d) Save all les: To save all the les for the current/selected project. (e) Undo: To undo the executed action. (f) Redo: To redo the undone action. (g) Cut: To cut the selected/highlighted part in editor. (h) Copy: To copy the selected/highlighted part in editor. (i) Paste: To paste the cut/copy message in editor. (j) Find: To nd required text in the le in active editor. 2 (k) Replace: To replace required text in the le in active editor by some alternate text. 3. Debugger tool bar: Debugger tool bar is shown in gure 4. Debugger tool bar is used to debug the current/selected project. The buttons in debugger toolbar are (from left to right) Debug/Continue, Run to cursor, Next line,Next instruction, Step into, Step out, Stop debugger, Debugging Windows and Various info. You will be able to understand the use of this buttons by rigorous practise of debugging various projects. Figure 4: Debugger Toolbar 4. Compiler tool bar: Compiler tool bar is shown in gure 5 and is used in building/compiling/running the current/se- lected project. The buttons in Compiler toolbar are (from left to right): Figure 5: Compiler Toolbar (a) Build: For building the current/selected project. (b) Run: For running the current/selected project. (c) Build and run: For building and running the current/selected project. (d) Rebuild: For rebuilding the current/selected project. (e) Abort: For aborting the build process for the current/selected project. (f) Build target: For dening the type of build target for current/selected project, either debug or release. 5. Manager: Manager is shown in gure 6. It is labelled as Management. This window provides the list of all the open projects and les for easy access to any required le of any project. Figure 6: Manager 6. Editor: Editor is shown in gure 7. Here, all the coding work will take place. It is provided in tabbed 3 fashion to work with many les at once. When no project is open, the start page or home page is displayed in editor. The links given in start page is divided into two parts and explained below Figure 7: Editor, Start/Home Page 7. Figure 8 is short-cut on Starting page of IDE for creating a new project and opening an already created project. It also contains link for Code::Block forum where many useful resources can be found along with other useful discussions. The link points to url http://forums.codeblocks.org/. The second and third link points to BerLiOS Developer Site aims at enriching the Open Source community by providing a centralized place for Open Source Developers to control and manage Open 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 les already opened in the IDE. It is link to few projects and les from history of IDE. 4 Figure 9: Shortcut to History of Projects Opened Using Code::Blocks 9. Logs: Log window is shown in gure 6. It is labelled as Logs & others. This window acts as log for various actions performed in IDE. All logs related to various activities can be checked at appropriate windows. Figure 10: Logs 5 3 Working with Code::Block on Windows In this section we discuss writing and building of three projects. First project (hello world.c) is a simple program which displays hello world on output. The second project (line.c) uses graphics.h header le and displays a line. The third project (3poly.cpp) uses simplecpp package and draws three polygons on output. For Windows (Windows 7) we will be using CodeBlocks-EP. CodeBlocks-EP comes with integrated WinBGIm (stands for Windows Borland Graphics Interface). In Windows, WinBGIm is required to run the programs with graphics.h header le. When CodeBlocks-EP is run for rst time a le association window is displayed as shown in gure 11. Select 3rd option Yes, associate Code::Blocks with c/c++ le types or 4th option Yes, associate Code::Blocks with every supported type(including project les from other IDEs) and click OK. Figure 11: File association window 3.1 Installation of Code::Block Code::Block used for windows is CodeBlocks-EP (stands for Code::Blocks - EDU Portable). WinBGIm (Borland Graphics Interface) required to run programs with graphics.h header is already integrated in CodeBlocks-EP. Download Codeblocks-EP from http://codeblocks.codecutter.org/ The installation steps are as given below. 1. Download Code::Block-EP installer from the link given above and browse to the appropriate di- rectory where the installer is downloaded. Click the .exe le downloaded and window as shown in gure 12 will pop up. Click Run. Figure 12: Click on Run 6 2. A new window appears as shown in gure 13. Click Next. Figure 13: Welcome to the CodeBlocks-EP Setup Wizard screen 3. The third windows that appears is of license agreement as shown in gure 14. Select I accept the agreement and click Next. Figure 14: License Agreement 7 4. The next window displays some important information (shown in gure 15) regarding Code::Block- EP. Kindly go through information and click on Next. Figure 15: Information window 5. Next window asks for location where the CodeBlock-EP will be installed. The default location will be C:\Program Files\CodeBlocks-EP. Figure 16 shows the location provided for CodeBlocks- EP installation. Provide appropriate location and click on Next. Figure 16: Providing location for CodeBlocks-EP installation 8 Figure 17 shows the location provided for CodeBlocks-EP shortcuts in Start Menu Bar. Click on Next. Figure 17: Providing folder for CodeBLocks-EP shortcuts Select the checkbox Create a desktop icon as shown in Figure 18. Click Next. 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 Install to 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 gure 21. If you want to launch the CodeBlock select Launch CodeBlocks-EP and click Finish. Figure 21: Completing the installation process 8. CodeBlocks IDE opens as shown in gure 22. Alternatively CodeBlocks-EP can be launched by double clicking the desktop icon created or clicking on its shortcut icon in Start Menu Bar. Figure 22: Code::Block IDE in Windows 7 11 3.2 Installation of Simplecpp The steps to be followed to install simplecpp are as listed below. Download the tar.gz le from http:// www.it.iitb.ac.in/frg/wiki/images/f/f3/Simplecpp-Windows.tar.gz. Untar the le and go into the simplecpps folder. The steps have been tested on Windows 7. 1. Close all the running instance of Codeblock-EP 2. Double click on .exe simplecpp le. A window is displayed as shown in gure 23. Click Run. Figure 23: Installation of simplecpp on windows 3. A new window opens which is labelled Setup - Simplecpp as shown in gure 24. Click on Next. Figure 24: Setup - Simplecpp 12 4. A new window is displayed to select path of installation as shown in gure 25. By default it is C:\ProgramFiles\Codeblocks-EP. If you want to change the installation path, click Browse, navigate to the directory, and click Ok, else leave it unchanged. Click Next. Figure 25: Selecting CodeBlocks-EPs installation folder 5. A new window stating that simplecpp is ready to install is displayed. This is shown in gure 26. Click Install. Figure 26: Install 13 6. Finally, click Finish to complete the installation as shown in gure 27. Figure 27: Finish Simplecpp installation 3.3 Writing a new C/C++ Program This section is divided into writing non-graphic program, writing graphic program using graphics.h header le and writing graphic program using simplecpp package. 3.3.1 Non-Graphic Project 1. Click on New le button. The New from template window as shown in gure 28 opens. For non-graphics projects, select Console application. When the type of project is selected the Go button 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 gure 29. Select checkbox Skip this page next time so that the page is not displayed again. Click Next Figure 29: New console application wizard 3. Next window enables user to select the language to be used for project as shown in Figure 30. Select C/C++. Here, C is selected for helloworld project. Click Next. 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 to create the project in. This is Shown in gure 31. After lling 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 gure 32. By default GNU GCC Compiler is selected. Click on Finish. Figure 32: Selecting compiler for the project 16 6. The project node opens in manager window as shown in gure 33. The project node is empty and we have to add les to the project. Figure 33: Project node with no les 7. To add les to the project select project node and click on Filein menu bar, then click on File... in options in New. The process is shown in gure 34. Figure 34: Adding le to the project 17 8. New from template opens as shown in gure 35. For our example select C/C++ source and click on Go. Figure 35: Selecting type of le to be added in the project 9. A new window is displayed as shown in gure 36. Select the checkbox Skip this page next time so 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 gure 37. We have selected C for our helloworld example. Figure 37: Select the language of the le added 11. Figure 38 shows the window that opens to add the le. click on ... beside Filename with full path. Figure 38: Details of le to be added 19 A window as shown in gure 39 opens. Select the folder of the project and enter le name to be added. Click on Save. Figure 39: Selecting the location and le name to be added When Save button is clicked the window in gure 38 opens again with full path and name of the le. Select Debug and Release. Shown in gure 40. Click on Finish. Figure 40: Finalize details of le to be added 20 12. Management window now shows project node which can be expanded. Click on project node and double click on hello.c to open the le in editor shown in gure 41 and gure 42 Figure 41: Project node with + sign indicating it can be expanded Figure 42: Project node expanded 13. When the hello.c le opens in editor, user can start coding. Code is shown in gure 43. Figure 43: Writing code in editor 21 3.3.2 Graphic Project using graphics.h 1. Click on New le button. The New form template window as shown in gure 28 opens. For graphics projects, select WinBGIm project. Go button gets highlighted (top right corner). Click on Go. Figure 44: New form template 2. When Go button is clicked a new window opens as shown in Figure 45. Select checkbox Skip this page next time so every time new project is created this window should not come. Click on Next. If 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 gure 46. For 22 the example hello world used in this manual select C 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 Add Console and Graphics only as shown in gure 47. Select Graphics only 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 to create the project. This is Shown in gure 48. After lling 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 gure 49. By default GNU GCC Compiler is 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 les to the project. To add les to the project select project node and click on File in menu bar, then click on File... in options in New. New from template opens as shown in gure 35. For our example select C/C++ source and click on Go. A new window pops out which have a checkbox Skip this page next time. Select the checkbox so this window should not open every time a new le is added to the project. Select the preferred language. For our example select C. A new window opens which allows user to add the les to the project. Click on ... beside Filename with full path. This is shown in Figure 38. A window as shown in gure 39 opens. Select the folder of the project and enter le name to be added. Click on Save (see steps 6-11 of section 5.2.1.1). Select Debug and Release. Shown in gure 50. Click on Finish. Figure 50: Finalize details of le to be added (for line project) 8. Management window now shows project node which can be expanded (gure 51). Figure 51: Project node with + sign indicating it can be expanded 25 9. Click on project node and double click on line.c to open the le in editor. When the line.c le opens in editor, user can start coding. Code is shown in gure 52. Figure 52: Writing program in editor (line project) 3.3.3 Graphic Project using simplecpp 1. Click on New le button. The New form template window as shown in gure 28 opens. For graphics projects using simplecpp, select Simplecpp project. Go button gets highlighted (top right corner). Click on Go. Figure 53: New from template 26 2. Next window asks the user to select type of project. The options are Add Console and Graphics only as shown in gure 54. Select Graphics only 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 to create the project. This is Shown in gure 55. After lling 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 gure 49. By default GNU GCC Compiler is 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 gure 57. We have to add les to the project. Figure 57: Empty project node in Management window 28 6. To add les to the project select project node and click on File in menu bar, then click on File... in options in New. Shown in gure 58. Figure 58: Adding les to empty project node 7. New from template opens as shown in gure 59. For our example select C/C++ source and click on Go. Figure 59: Selecting c/c++ source for project 29 8. Select the preferred language. For our example select C++ (gure 60). Figure 60: Selecting language for the le to be added A new window opens which allows user to add the les to the project. Click on ... beside Filename with full path. This is shown in Figure 38. A window as shown in gure 61 opens. Select the folder of the project and enter le name to be added. Click on Save. Figure 61: Giving location and name of the le to be added 30 In next window select Debug and Release. Shown in gure 62. Click on Finish. Figure 62: Finalize details of le to be added 9. Management window now shows project node which can be expanded (gure 63). Figure 63: Project node with + sign indicating it can be expanded 31 10. Click on project node and double click on 3poly.cpp to open the le in editor. When the 3poly.cpp le opens in editor (gure 64), user can start coding. Code is shown in gure 65. Figure 64: opening le in editor Figure 65: coding 32 3.4 Building the Project The process to build the graphics and non-graphics project is same, just Click on Build and then Run (or directly on Build and run). The output for the program used is shown in gure 66 for hello world project, gure 67 for line project and gure 68 for 3poly project. Figure 66: Output of hello world project Figure 67: Output of line project Figure 68: Output of 3poly project 33 3.5 Opening existing program/project Click on Open button 69. Browse to desired directory and open the le with .cbp extension as shown in gure 70. Figure 69: Selecting Open under le in Menu Bar Figure 70: Select le with .cbp extension to open an existing project 34 4 Working with Code::Block on Ubuntu In this section we discuss writing and building three projects. First project (hello world.c) is simple program which displays hello world on output. The other project (line.c) uses graphics.h header le and displays a line. graphics.h is not supported by gcc, which is the default C/C++ compiler on Ubuntu. The third project (3poly.cpp) uses simplecpp package and draws three polygons on output. We have to install some packages, include few libgraph libraries during building the project with graphic.h header le. 4.1 Installation of Code::Blocks Pre-requisite for installing Code::Block is libwxgtk which is available in ubuntu software center. This package will be already installed in your system 3 . It is also advised to install build-essential package and update repository list. In case the libwxgtk is not installed, it can be installed from command line using command given in listing 1 [3]. Code::Block is available in Ubuntus repository. It can be installed using Ubuntu Software Center or it can also be installed using command line as given in listing 2. 1 $ sudo aptget i n s t a l l l i bwxgtk2 .80 2 $ sudo aptget i n s t a l l bui l de s s e n t i a l 3 $ sudo aptget update Listing 1: Installing libwxgtk2.8-0 using command line 1 $ sudo aptget i n s t a l l codebl ocks Listing 2: Installing Code::Blocks using command line Figure 71: Code::Block in Ubuntu Software Center Figure 72: Installing Code::Block using command line 3 Check for the libwxgtk version available for your Ubuntu, minimum required version for Code::Block to run is 2.0, version available on Ubuntu 12.04 is 2.8 35 Figure 71 shows Code::Block along with its logo in Ubuntu Software Center, while gure 72 shows installation of Code::Block using command line. In gure 72 four underlined lines are: line 1: Command to install the Code::Block. line 2: Packages installed along with Code::Block. line 3: Packages suggested along with Code::Block installation. libwxgtk2.8 4 package as mentioned above is already installed in your system. libwxgtk2.8-dev package is not required. line 4: Final list of packages that will be installed in your system When command line prompts for [Y/n] enter y and press enter. When Code::Block is run for rst time, It asks for default compiler. Select the appropriate compiler to proceed further. We have used GNU GCC Compiler. 4.2 Installation of packages for graphics.h header le GCC compiler does not support graphics.h, conio.h, windows.h and few other header les that works on Turbo C or Borland C. graphics.h header les enables programmer to write simple c/c++ graphics programs. In Ubuntu, gcc is default c/c++ compiler, thus, we have to make some settings, for gcc to support graphics[4]. We will start with installing some packages from command line as given in listing 3 1 $ sudo aptget i n s t a l l l i bs dl image1 . 2 l i bs dl image1.2dev gui l e 1.8 gui l e 1.8dev l i b s d l 1 . 2 debi an l i ba r t 2.0dev l i b a u d i o f i l e dev l i bes d0 dev l i bdi r e c t f b dev l i bdi r e c t f b ext r a l i bf r e e t ype 6 dev l i bxe xt dev x11protoxextdev l i bf r e e t y pe 6 l i baa1 l i baa1 dev l i bs l ang2 dev l i bas ound2 l i basound2dev Listing 3: Installing required packages to support graphics.h After the above mentioned packages are installed, download the libgraph package (download link given in footnote 5 ) and untar it in home directory. For this untarring tool must be installed on system. Open the command line and follow the instructions given in listing 4. 1 $ cd l i bgr aph 1. 0. 2 2 $ . / c onf i gur e 3 $ sudo make 4 $ sudo make i n s t a l l 5 $ sudo cp / usr / l o c a l / l i b / l i bgr aph . / usr / l i b Listing 4: Installing libgraph package using command line 4.3 Installation of Simplecpp Download the simplecpps tar package and untar it. The tar le can be downloaded from the link given in footnote 6 . Change to the simplecpp directory and run the command sh congure.sh. Shown in gure 73. 1 $ cd DIRECTORY WHERE Simplecpp. tar IS DOWNLOADED 2 $ t ar xvf Si mpl ecpp . t ar 3 $ cd si mpl ecpp/ 4 $ sh c onf i gur e . sh Listing 5: Installing simplecpp package using command line 4 Details about above mentioned packages can be found at http://packages.ubuntu.com/precise/allpackages. 5 http://download.savannah.gnu.org/releases/libgraph/libgraph-1.0.2.tar.gz 6 http://www.it.iitb.ac.in/frg/wiki/images/4/45/Simplecpp.tar 36 Figure 73: Installing simplecpp The last line in installation process mentions To compile use: /home/sandeep/Projects/reports/code- blocks/simplecpp/s++ lename.cpp. The path to simplecpp/s++ will vary from user to user as per users machine, this path is location of simplecpp/s++ on the machine. Shown in gure 74. Figure 74: location of simplecpp/s++ For the project using simplecpp package some setting has to be changed. The steps to make the required changes are as given below. 1. Open Code::Blocks and click on Setting and select Complier and Debugger.... A window labelled Compiler and debugger settings will open as shown in Figure 76. By default the selected compiler is GNU GCC Compiler. Click Copy highlighted with red box in gure 76. A window as shown in gure 75 will open. Write simplecpp and click Ok. Figure 75: Copying the compiler 37 2. A message stating change the appropriate setting in Toolchain executable is displayed, which is shown in gure 76. 3. Click on Toolchain executables tab highlighted with red box in gure 76. Figure 76: Compiler and debugger settings 38 4. Change the compiler path of Code::Blocks to that of simplecpp. The steps are given below. 5. Click all ... buttons highlighted with red box in gure 77) on by one. Change all the settings as shown in gure. When ... is clicked, browse to the /simplecpp directory. This is shown in gure 78. s++ and makes++ are available in /simplecpp/ folder. libsprite.a is available in /simplecpp/lib/ folder. Figure 77: Changes to be made in Toolchain Executables 6. To summarize, the list of all the elds that need to be changed is given below (a) Compilers installation directory: /simplecpp/ (b) C compiler: /simplecpp/s++/ (c) C++ compiler: /simplecpp/s++/ (d) Linker for Dynamic libs: /simplecpp/s++/ (e) Linker for static libs: /simplecpp/s++/libsprite.a (f) Make program: /simplecpp/makes++/ 7. When all the required elds are changed, click on Additional Paths shown in red block in gure 77. 39 Figure 78: Simplecpps directory 8. In Additional Paths click on Add shown in red block in gure 79. Browse to /simplecpp/ directory and click on Ok. User will return on Compiler and debugger setting window. Click Ok again to exit settings and return to editor. Figure 79: Additional Paths settings 40 4.4 Writing a new c/c++ program 1. Click on New le button. The New from template window opens as shown in gure 80. Select the type of project you want to program in. When the type of project is selected the Go button gets highlighted (top right corner). Select Console application and click on Go. Figure 80: Starting a new project 2. When Go button is clicked, a new window opens as shown in gure 81. This window enables the user 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 user wishes to create the project in. This is shown in gure 82. After lling in the details click Next. Figure 82: Title for Project 4. Next window is to select the compiler. By default GNU GCC Compiler is selected. In this window, the user can change the compiler to be used as per the use and requirements. Non-graphic and Programs including graphics.h header le: Select GNU GCC Compiler (gure 83) Simplecpp programs: Select Simplecpp (gure 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 gure 85. Project node can be expanded to see the main.c le. Figure 85: Project Node when Expanded 43 When main.c le is clicked, it opens in editor as shown in gure 86 for hello world project. Figure 86: Project Node when Expanded for helloworld.c (with code shown in editor) 6. Code used for graphics program (line) is shown in gure 87. Figure 87: Project node when expanded for line.c (with code shown in editor) 44 7. Code used for simplecpp program (3poly) is shown in gure 88. Every project involving simplecpp has to include simplecpp package as seen in rst line of the code. Figure 88: Project node when expanded for 3poly.cpp (with code shown in editor) 8. While using Code::Blocks for the rst time, some extra windows will be displayed. In this manual only the important windows are shown. 4.5 Building the Project 4.5.1 Non-Graphics Project After the code is written, project needs to be built. Click on build and run from compiler bar. Output is as shown in gure 89. Figure 89: Output for helloworld.c 4.5.2 Graphics Project using graphics.h To build a program involving graphics.h, it is recommend to enable full logging in Code::Block. Full logging also helps in better debugging. Steps to enable full Full logging in Code::Block is given in appendix C 45 Now the project using graphics.h (line) has to be linked with libraries copied in /usr/lib while installing libgraph 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 Project build options as shown in gure 90 pops up. Option to change the compiler selected for the project is also available in this window. Figure 90: Project build options 2. In Project build options window, click on linker settings tab. This tab is shown in gure 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 a small window titled Add library opens as shown in gure 92. Figure 92: Interface for adding libraries 4. Click on dotted button to right of box. A new window opens as shown in gure 93. This window enables user to browse to appropriate folder and to select required library. Browse to the /usr/lib directory. All the required library les are not visible. Select all les in dropdown placed at the bottom, to enable visibility of all types of les. Select all the libgraph .* les, except libgraph.la le. Files to be selected are shown in the gure 93. Figure 93: Files/libraries to be added for graphic projects 47 5. Libraries shown in Ubuntu 12.04, 32-bit OS are libgraph.a, libgraph.so, libgraph.so.1, libgraph.so.1.0.2, libgraph.so.4 and libgraph.so.4.0.0. In Ubuntu 12.04, 64-bit OS libraries libgraph.so.4 and lib- graph.so.4.0.0 are not available. Select all the libgraph.* les except libgraph.la 6. After selecting all the required libraries click on Open. A new window labelled Question will open asking Keep this as relative path as shown in gure 94. Click on No. Figure 94: Relative or absolute path for les/libraries 7. The libraries will be linked using absolute path as shown in gure 95. Click on Ok. Figure 95: libraries selected 48 8. We are now re-directed to linker settings tab. The added libraries are shown. In Other linker options window write -lgraph . The nal setup is shown in gure 96 with all the required 6 libraries and -lgraph. Click on Ok to get back to editor. Now we are ready to build the project with graphics.h header le Figure 96: Libraries added to project 9. Now click the build and run button from compiler bar and output will be displayed as shown in gure 97. Figure 97: Output for line.c 49 4.5.3 Graphics Project using simplecpp To build a program involving simplecpp, it is recommend to enable full logging in Code::Block. Full logging also helps in better debugging. Steps to enable full Full logging in Code::Block is given in appendix C Click the build and run button from compiler bar and output will be displayed as shown in gure 98. Figure 98: Output for 3poly.cpp 50 4.6 Opening Existing Program/Project Click File and select Open. Browse to desired directory and select the le with .cbp extension as shown in gure 99 and click on Open. Figure 99: Select le with .cbp extension to open an existing project 51 References [1] The Code::Block Team. Code::block homepage http://www.codeblocks.org/. [2] The Code::Block Team. Gpl v3.0 license http://www.codeblocks.org/license. [3] Installing code::block on ubuntu http://wiki.codeblocks.org/index.php?title=Installing_Code::Blocks_from_source_on_ Linux. [4] Eternal thinker: How to use graphics.h in ubuntu? http://blog.eternal-thinker.com/2010/09/how-to-use-graphicsh-in-ubuntu.html. [5] Code::block faqs http://wiki.codeblocks.org/index.php?title=FAQ. 52 A Code used for Windows A.1 helloworld.c 1 #i nc l ude <s t di o . h> 2 3 i nt main ( ) 4 { 5 pr i nt f ( Hel l o worl d ! \ n) ; 6 r et ur n 0; 7 } Listing 6: helloworld.c A.2 line.c 1 #i ncl ude <s t di o . h> 2 #i ncl ude <gr aphi cs . h> 3 i nt main ( ) 4 { 5 i nt gd , gm; gd=DETECT; 6 i ni t gr aph(&gd,&gm, NULL) ; 7 l i n e ( 50 , 50 , 80 , 80) ; 8 del ay ( 5000) ; 9 r et ur n 0; 10 } Listing 7: line.c A.3 3poly.cpp 1 #i nc l ude <si mpl ecpp> 2 3 main program{ 4 i ni t Canvas ( ) ; 5 Tur t l e t1 , t2 , t3 ; 6 7 t2 . l e f t ( 120) ; 8 t3 . l e f t ( 240) ; 9 10 r epeat ( 8) { 11 t1 . f orward ( 100) ; 12 t2 . f orward ( 100) ; 13 t3 . f orward ( 100) ; 14 15 t1 . l e f t ( 360. 0/8) ; 16 t2 . l e f t ( 360. 0/8) ; 17 t3 . l e f t ( 360. 0/8) ; 18 } 19 wai t ( 5) ; 20 } Listing 8: 3poly.cpp 53 B Code used for Ubuntu B.1 helloworld.c 1 #i nc l ude <s t di o . h> 2 3 i nt main ( ) 4 { 5 pr i nt f ( Hel l o worl d ! \ n) ; 6 r et ur n 0; 7 } Listing 9: helloworld.c B.2 line.c 1 #i nc l ude <s t di o . h> 2 #i nc l ude <gr aphi cs . h> 3 4 i nt main ( ) 5 { 6 i nt gd , gm; gd=DETECT; 7 i ni t gr aph(&gd,&gm, NULL) ; 8 l i n e ( 50 , 50 , 80 , 80) ; 9 del ay ( 5000) ; 10 11 r et ur n 0; 12 } Listing 10: line.c B.3 3poly.cpp 1 #i nc l ude <si mpl ecpp> 2 3 main program{ 4 i ni t Canvas ( ) ; 5 Tur t l e t1 , t2 , t3 ; 6 7 t2 . l e f t ( 120) ; 8 t3 . l e f t ( 240) ; 9 10 r epeat ( 8) { 11 t1 . f orward ( 100) ; 12 t2 . f orward ( 100) ; 13 t3 . f orward ( 100) ; 14 15 t1 . l e f t ( 360. 0/8) ; 16 t2 . l e f t ( 360. 0/8) ; 17 t3 . l e f t ( 360. 0/8) ; 18 } 19 wai t ( 5) ; 20 } Listing 11: 3poly.cpp 54 C Enabling full logging in Code::Block Logging can be used extensively for many purposes including debugging and proling. Steps to enable full logging in Code::Block [5] are as mentioned below. Settings Compiler and debugger settings Global compiler settings check Selected compiler Other settings Compiler logging 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 above in right panel. Here we can change the default compiler. 3. Click on right arrow beside tabs to select Other settings. 4. The rst option is of Compiler logging, select Full command line. 55
Data Security: Technical And Organizational Protection Measures Against Data Loss And Computer Crime 1st Edition Thomas H. Lenhard all chapter instant download