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 http://horstmann.com/ccc.html . 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:
g++ -o executable_name source_fileFor example,
g++ -o hello hello.cpp
g++ -o executable_name -I c:\cccbook\cccfiles source_file c:\cccbook\cccfiles\ccc_time.cppFor example,
g++ -o time1 -I c:\cccbook\cccfiles time1.cpp c:\cccbook\cccfiles\ccc_time.cppAlternatively, 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.* .For example,
g++ -o executable_name source_file ccc_time.cpp
g++ -o time1 time1.cpp ccc_time.cpp
g++ -D CCC_MSW -I c:\cygwin\usr\include\w32api -I c:\cccbook\cccfiles -o executable_nameThe command must be typed on a single line.
source_file c:\cccbook\cccfiles\ccc_msw.cpp c:\cccbook\cccfiles\ccc_shap.cpp -luser32 -lgdi32
g++ -D CCC_MSW -I c:\cygwin\usr\include\w32api -I c:\cccbook\cccfiles -o phoenixAlternatively, 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.
phoenix.cpp c:\cccbook\cccfiles\ccc_msw.cpp c:\cccbook\cccfiles\ccc_shap.cpp -luser32 -lgdi32
g++ -D CCC_MSW -I c:\cygwin\usr\include\w32api -o executable_name source_fileFor example,
ccc_msw.cpp ccc_shap.cpp -luser32 -lgdi32
g++ -D CCC_MSW -I c:\cygwin\usr\include\w32api -o phoenixFor the "ASCII art" version of the graphics library, use
phoenix.cpp ccc_msw.cpp ccc_shap.cpp -luser32 -lgdi32
g++ -D CCC_ASC -I c:\cccbook\cccfiles -o executable_nameFor example,
source_file c:\cccbook\cccfiles\ccc_asc.cpp c:\cccbook\cccfiles\ccc_shap.cpp
g++ -D CCC_ASC -I c:\cccbook\cccfiles -o phoenix
phoenix.cpp c:\cccbook\cccfiles\ccc_asc.cpp c:\cccbook\cccfiles\ccc_shap.cpp
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