Many C++ newbies want to create the projects they find in books by typing in the code they come across to better see how the process works. However, sometimes just getting the project started can be a serious problem. You may find step-by-step instructions online that provide you with techniques you can use to create the projects, but often, these procedures build on what you've done before. The following steps help you get a project started that includes a header, even if you jump to this point directly without getting all the prep work done. Even though the screenshots show a Windows system, the same procedure works with both the Mac and Linux platforms.
Open your copy of Code::Blocks using a technique appropriate for your operating system.
You see the Code::Blocks IDE open with the Start Here tab opened.
Choose File→New→Project or click Create a New Project on the Start Here page that appears when you start the application.
The New from Template dialog box appears.
In the New from Template dialog box, click the Console Application icon found in the Projects tab, then click Go.
You may see the Welcome page of the Console Application wizard. If so, click Next to get past it. The first usable page asks which language you want to use.
Highlight C++ and click Next.
You see a list of project-related questions. These questions define project basics, such as the project name.
Type a name for your project in the Project Title field and a location for your project in the Folder to Create Project In field.
The example uses SampleProject as the project title. However, you need to give your project a name that matches the application you want to create. Notice that the wizard automatically starts creating an entry for you in the Project Filename field. It's best to simply use the default name in the Project Filename field.
Click Next.
You see the compiler settings. Most of the projects in this book use the default compiler settings, which means using the GNU GCC Compiler option in the Compiler drop down list box. However, if you look at the Compiler drop-down list, you see that Code::Blocks supports a number of compilers and you can add more to the list. The other settings control the creation and location of a Debug version (the version you use for finding problems in your code) and a Release version (the version that you send to a customer) of the application.
Change any required compiler settings and click Finish.
The wizard creates the application for you. It then displays the Code::Blocks IDE with the project loaded. However, the source code file isn't loaded yet. To load the source code file, you simply double click its entry in the Workspace hierarchy (such as main.cpp).
Highlight the project entry (such as Sample Project) and choose File→New→File.
The New from Template dialog box shows the kinds of files you can add to your project.
Highlight one of the file types, such as C/C++ Header or C/C++ Source, and click Next.
You see the appropriate wizard for the kind of file you're adding. This article assumes you're adding a header file. If you see a welcome page, simply click Next to get past it.
Configure the header file as needed for your project.
Type a filename in the Filename with Full Path field.
Check individual build options or click All to add the header to all of the builds for this project. (All is the best selection for the book).
You must provide a full path to the filename. Notice that the IDE automatically creates a Header Guard Word field entry for you — that prevents the compiler from adding the header to a project more than once. Using this default normally works just fine.
Click Finish.
The IDE creates the new file for you and automatically opens it for editing.
You can repeat steps 10 through 12 as often as needed to create the entire project hierarchy. The process for adding a C++ source file is about the same as adding a header file. The only difference is that you don't need to add a header guard word. Each time you add a new file, the IDE will add it to the project hierarchy and automatically open the file for you.