Beginning Programming with C++ For Dummies. Davis Stephen R.
Чтение книги онлайн.
Читать онлайн книгу Beginning Programming with C++ For Dummies - Davis Stephen R. страница 9
When you’ve completed the installation of Code::Blocks, you may choose to return to this window and restore the settings to Mac App Store.
Figure 2-7: You’ll need to allow third-party applications to be installed before you can install Code:: Blocks on your Macintosh.
6. Double-click the Code::Blocks icon.
The first time you do this, the Mac OS asks, “Are you sure you want to open it?”
7. Select Don’t Warn Me When Opening Applications on This Disk Image and click Open.
Code::Blocks should start and find the gcc compiler installed with the Command Line Tools.
8. Select the gcc compiler, as shown in Figure 2-8. Click Set as Default and then click OK to continue starting Code::Blocks.
Code::Blocks opens with a banner page, followed by a menu across the top of the dialog box.
Continue to the next section, “Setting Up Code::Blocks.”
Figure 2-8: Code:: Blocks automatically finds the gcc compiler the first time you execute it.
The GNU C++ compiler that comes with Code::Blocks supports a myriad of options; all of them affect the way it reads your programs. For this book, you’ll need to make sure that a few of these options are set. The instructions in this section are the same whether you’re using Windows, Linux, or Mac OS.
1. Start Code::Blocks if it isn’t started already.
In Windows, you can use the icon that Code::Blocks installed on the desktop. A window similar to Figure 2-9 appears. (The details of this opening screen vary by operating system and by version. This is the opening screen from the Version 13.12.)
2. Choose Settings⇒Compiler from the menu options.
A window similar to Figure 2-10 appears.
3. Select Global Compiler Settings from the options on the left side of the window.
Figure 2-9: The opening screen of the Code:: Blocks environment.
Figure 2-10: The compiler settings window allows the user to adjust the details of the way the C++ compiler works.
4. Select the Compiler Flags tab.
This displays the compiler options.
5. Select the Enable All Compiler Warnings check box.
This will cause the GNU C++ compiler to complain about anything that it sees that might be a problem. Turning on all warnings is a good idea when you’re first learning a language – or when you’ve been programming for over 30 years (like me).
6. Select the Have g++ Follow the C++11 ISO C++ Language Standard check box.
The most recent upgrade to the C++ standard was adopted in 2011. This upgrade implements several new features, many of which are beyond the scope of this book. Some of these features actually make life easier, however, so you’ll want to use them. Selecting this check box gives you access to these useful extensions.
7. Select OK.
The Settings window closes.
In this section, you’ll build a default program that comes with Code::Blocks. This program does nothing more than display Hello, world! on the display, but building and running this program successfully will verify that you’ve installed Code::Blocks properly.
Start Code::Blocks by double-clicking the Code::Blocks icon created on the Desktop or selecting Programs⇒Code::Blocks⇒Code::Blocks. This should open a window like the one shown in Figure 2-9.
Across the top of the window are the usual menu options, starting with File, Edit, View, and so on. The window at the upper right, the one that says “Start here,” is where the source code will go when you get that far. The window at the lower right is where Code::Blocks displays messages to the user. Compiler error messages appear in this space. The window on the left labeled Management is where Code::Blocks keeps track of the files that make up the programs. It should be empty now since you have yet to create a program. The first thing to do is create a project.
Okay, what’s a project?
You want Code::Blocks to create only Console Applications, but it can create a lot of different types of programs. For Windows programmers, Code::Blocks can create Dynamic Link Libraries (also known simply as DLLs). It can create Windows applications. It can create both static and dynamically linked libraries for Linux and Mac OS.
In addition, Code::Blocks allows the programmer to set different options on the ways each of these targets is built. (Later chapters show you how to adjust a few of these settings.) And finally, Code::Blocks remembers how you have your windows configured for each project. When you return to the project, Code::Blocks restores the windows to their last configuration to save you time.
Code::Blocks stores the information it needs about the type of program that you’re building, the optional settings, and the window layout in two project files. The settings are stored in a file with the same name as the program but carrying the extension .cbp. The window configuration is stored in a file with the same name but with the extension .layout.
1. Select File⇒New⇒Projects to open the window shown in Figure 2-11.
This is a list of all of the types of applications that Code::Blocks knows how to build.
Fortunately, you’ll be concentrating on just one, the Console Application.
Figure 2-11: Select the Console Application from the many types of targets offered.
2. Select Console Application and select Go.
Code::Blocks responds with the display shown in Figure 2-12. Here Code::Blocks is offering you the option to create either a C or a C++ program.
3. Select C++ and click Next.