C++ Data Structures from Scratch
by Robert MacGregor
Home >>
Vol. 1 >>
Vol. 2 >>
Vol. 3.1 >>
Vol. 3.2 >>
Purchase >>
More
Generating an Executable
for Vol. 1, Chapter 1.3
Now that we've installed the IDE and downloaded the source code, we can build and run the programs discussed in
the book.
The first three parts of this tutorial (Creating the Project, Configuring the Project, and Copying
the Source Code) you'll only need to perform once.
- Creating the Project in Code::Blocks
-
Click File (at the top left), New, then Project...
-
Click Empty project, then Go.
-
Click Next.
-
For the Project title, enter cpp_data_structures. For the Folder to create project in, enter
c:\. Click Next.
-
For the Compiler, select GNU GCC Compiler.
-
Check Create "Debug" configuration, and uncheck Create "Release" configuration. Click
Finish.
- Configuring the Project
-
Click Project (at the top left), then Build options...
-
Check Have g++ follow the C++11 ISO C++ language standard, and Static linking.
-
Click Search directories, then Add (near the bottom), then OK.
-
The text box (underneath Policy) should now contain c:\cpp_data_structures\. Click OK.
-
Click File (at the top left), then Save project.
- Copying the Source Code into the Project Folder
-
Copy all of the source code folders that you downloaded (dss, ds2, ds3) into
c:\cpp_data_structures\.
-
Depending on which volume(s) you own, your source code should now be in the following folders:
-
c:\cpp_data_structures\dss\
-
c:\cpp_data_structures\ds2\
-
c:\cpp_data_structures\ds3\
- Adding Source Files to the Project
-
As shown at the top of Chapter 1.3, we'll need every file in the folder dss\hello.
-
Click Project (at the top left), then Add files...
-
Navigate to c:\cpp_data_structures\dss\hello\, select main.cpp, then click Open.
-
Click cpp_data_structures (on the left-hand side, under Management, Projects, and
Workspace).
-
Repeatedly press the right arrow key, until you see Sources, dss, hello, and
main.cpp.
-
This is called the project tree, which shows all of the files in the project (click here to view).
-
Double-click main.cpp, to open it in the text editor.
-
The numbers 1 - 46 are line numbers, which are referenced heavily throughout the book.
-
Building and Running the Executable
-
Now that we've added the required source files to the project, we can build and run the executable.
-
Click Build (at the top), then Build and run. The black console window displays the
program's output.
-
Reposition the console window, such that you can view the source code and output side-by-side.
-
Continue reading Chapter 1.3, following along with the source code and output on the screen.
-
Upon reaching the end of Chapter 1.3, return here and complete the remainder of the tutorial.
-
Removing Files from the Project
-
Before beginning the next chapter, we need to remove the current chapter's source files from the project.
-
Close the console window, via the Press any key to continue prompt.
-
Right click main.cpp (in the project
tree), then Remove file from project.
-
Click Build (at the top), Clean, then Yes.
-
We can now add the next chapter's source files, then build and run the executable.
-
Reopening the Project
-
To reopen the project later, click File (at the top left), then Open...
-
Select c:\cpp_data_structures\cpp_data_structures.cbp, and click Open.
-
The file extension .cbp stands for Code::Blocks project.
Back