Computing Concepts with C++ Essentials

Compiler and Tool Help

Gnu g++ on Microsoft Windows

You simply must be able to work with files and directories (also called folders). Computers have become so easy to use that many casual computer users seem to have no idea where their computer stores data. If you are such a user, you need to learn more about files and directories. See the links at the end of this page for tutorials.

The g++ compiler can be freely downloaded in a number of forms. The easiest method is to install Cygwin, following these instructions . Cygwin includes the g++ compiler. 

Install Cygwin into c:\cygwin, or modify the instructions below if you use a different installation directory.

You also need a text editor. You can use Notepad for very simple programs, but you should get a better editor such as Textpad or Emacs .

You invoke the compiler from a command shell (also called a DOS shell). If you never used the DOS shell and don't know how to manoeuver around the file system with the cd command, you'll need to learn that first. See the links at the end of this page for tutorials.

If you want to compile programs that use the Time/Employee classes or CCC graphics, then you need to download and unzip the programs for this book from . Unzip all files into a directory such as c:\cccbook. If you choose a different installation directory, modify these instructions accordingly.

Here are the instructions for compiling programs:

Programs that don't include the Time/Employee classes or CCC graphics:

g++ -o executable_name source_file
For example,
g++ -o hello hello.cpp

Programs that include the Time or Employee class:

Here are the directions for the Time class. To use the Employee class, simply replace ccc_time with ccc_empl.
Compile with the following command:
g++ -o executable_name -I c:\cccbook\cccfiles source_file c:\cccbook\cccfiles\ccc_time.cpp
For example,
g++ -o time1 -I c:\cccbook\cccfiles time1.cpp c:\cccbook\cccfiles\ccc_time.cpp
Alternatively, you can simply copy ccc_time.cpp and ccc_time.h from the c:\cccbook\cccfiles directory into the same directory as the program that uses them, and compile with a simpler command line.
copy c:\cccbook\cccfiles\ccc_time.* .
g++ -o executable_name source_file ccc_time.cpp
For example,
g++ -o time1 time1.cpp ccc_time.cpp

Programs that use CCC graphics:

g++ -D CCC_MSW -I c:\cygwin\usr\include\w32api -I c:\cccbook\cccfiles -o executable_name 
source_file c:\cccbook\cccfiles\ccc_msw.cpp c:\cccbook\cccfiles\ccc_shap.cpp -luser32 -lgdi32
The command must be typed on a single line.
For example,
g++ -D CCC_MSW -I c:\cygwin\usr\include\w32api -I c:\cccbook\cccfiles -o phoenix
phoenix.cpp c:\cccbook\cccfiles\ccc_msw.cpp c:\cccbook\cccfiles\ccc_shap.cpp -luser32 -lgdi32
Alternatively, you can copy ccc_win.h, ccc_msw.h, ccc_msw.cpp , ccc_shap.h, and ccc_shap.cpp from the c:\cccbook\cccfiles directory into the same directory as the program that uses them, and compile with a simpler command line.
g++ -D CCC_MSW -I c:\cygwin\usr\include\w32api -o executable_name source_file 
ccc_msw.cpp ccc_shap.cpp -luser32 -lgdi32
For example,
g++ -D CCC_MSW -I c:\cygwin\usr\include\w32api -o phoenix
phoenix.cpp ccc_msw.cpp ccc_shap.cpp -luser32 -lgdi32
For the "ASCII art" version of the graphics library, use
g++ -D CCC_ASC -I c:\cccbook\cccfiles -o executable_name 
source_file c:\cccbook\cccfiles\ccc_asc.cpp c:\cccbook\cccfiles\ccc_shap.cpp
For example,
g++ -D CCC_ASC -I c:\cccbook\cccfiles -o phoenix
phoenix.cpp c:\cccbook\cccfiles\ccc_asc.cpp c:\cccbook\cccfiles\ccc_shap.cpp

Compiling wxWidgets Programs in Microsoft Windows

Unfortunately, this is harder than it should be. First, you need to make a resource file for each application. That is a file that has the same name as your program but extension .rc. It needs to contain the single line

#include "wx/msw/wx.rc"

Moreover, the compilation command is so complex that you need to use a make file. Run the command

make -f c:\wxWidgets\src\makeprog.g95 WXWIN=c:\wxWidgets TARGET=program name OBJECTS=object file(s)

The object files are obtained from the source files by replacing the .cpp extension with .o. For example,

make -f c:\wxWidgets\src\makeprog.g95 WXWIN=c:\wxWidgets TARGET=button OBJECTS=button.o

Useful Links