Computing Concepts with C++ Essentials/Big C++

Compiler and Tool Help

Gnu g++ on Linux/Unix/Mac OS X

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/bigcpp.html#code . Unzip all files into a directory such as ~/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 direction 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 ~/cccbook/cccfiles source_file ~/cccbook/cccfiles/ccc_time.cpp
For example,
g++ -o time1 -I ~/cccbook/cccfiles time1.cpp ~/cccbook/cccfiles/ccc_time.cpp
Alternatively, you can simply copy ccc_time.cpp and ccc_time.h from the ~/cccbook/cccfiles directory into the same directory as the program that uses them, and compile with a simpler command line.
cp ~/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++ -I ~/cccbook/cccfiles -o executable_name 
source_file ~/cccbook/cccfiles/ccc_x11.cpp ~/cccbook/cccfiles/ccc_shap.cpp -L /usr/X11R6/lib -lX11

The command must be typed on a single line.

For example,

g++ -I ~/cccbook/cccfiles -o phoenix
phoenix.cpp ~/cccbook/cccfiles/ccc_x11.cpp ~/cccbook/cccfiles/ccc_shap.cpp -L /usr/X11R6/lib -lX11

Caution: With Mac OS X Mountain Lion, you need to add -I /opt/X11/include after g++.

Alternatively, you can copy ccc_win.h, ccc_x11.h, ccc_x11.cpp, ccc_shap.h, and ccc_shap.cpp from the ~/cccbook/cccfiles directory into the same directory as the program that uses them, and compile with a simpler command line.

g++ -o executable_name source_file ccc_x11.cpp ccc_shap.cpp -L /usr/X11R6/lib -lX11
For example,
g++ -o phoenix phoenix.cpp ccc_x11.cpp ccc_shap.cpp -L /usr/X11R6/lib -lX11
For the "ASCII art" version of the graphics library, use
g++ -D CCC_ASC -I ~/cccbook/cccfiles -o executable_name 
source_file ~/cccbook/cccfiles/ccc_asc.cpp ~/cccbook/cccfiles/ccc_shap.cpp
For example,
g++ -D CCC_ASC -I ~/cccbook/cccfiles -o phoenix
phoenix.cpp ~/cccbook/cccfiles/ccc_asc.cpp ~/cccbook/cccfiles/ccc_shap.cpp
For the wxWidgets version of the graphics library, use
gcc -o executable_name -DCCC_WXW -I ~/cccbook/cccfiles `wx-config --cflags` 
source_file ~/cccbook/cccfiles/ccc_x11.cpp ~/cccbook/cccfiles/ccc_shap.cpp `wx-config --libs`
For example,
gcc -o phoenix -DCCC_WXW -I ~/cccbook/cccfiles `wx-config --cflags` 
phoenix.cpp  ~/cccbook/cccfiles/ccc_x11.cpp ~/cccbook/cccfiles/ccc_shap.cpp `wx-config --libs`

Compiling wxWidgets Programs

Note that the wxWindows library has changed the name to wxWidgets.

You first need to build the library. Download the file wxGTK-2.x.y.tar.gz (where 2.x.y is the current version number) from http://www.wxwidgets.org/. Type the following commands in a shell window:

cd the directory into which you downloaded the file
tar xvfz wxGTK-2.x.y.tar.gz
cd wxGTK-2.x.y
./configure
make
sudo make install

Supply your root password when prompted.

(If you can't run sudo, instead execute su, provide the root password, and then make install.)

Check /etc/ld.so.conf and make sure that it contains /usr/local/lib. If not, edit the file (as super user) and add that line.

Run sudo /sbin/ldconfig (or execute su and /sbin/ldconfig.)

On Mac OS X, you use wxMac-2.4.2.tar.gz instead; the other instructions are the same.

Once you have built the library, compiling applications is fairly simple, thanks to the handy wx-config utility. Simply use

gcc -o executable_name `wx-config --cflags` source_file `wx-config --libs`
For example,
gcc -o button `wx-config --cflags` button.cpp `wx-config --libs`