Source Code

This page provides the complete set of source code examples contained within the text of API Design for C++. Feel free to download and play with these samples yourself. They were designed to be as simple as possible, while still being useful and illustrative. Many thanks to the following people who have contributed fixes to the code: Danyu Liu, Steve Sperandeo, Mario Shraiki, and Tomek Drabas.

Build System

I have used the cross-platform CMake build system to facilitate compiling and linking the examples, so they should work on Windows, Mac OS X, and most UNIX operating systems. You will need to download and install CMake for your platform first though, if you don’t already have it installed: www.cmake.org

Building From The Command Line (Linux/Mac/Windows)

With the cmake command in your path, you can simply do the following to create a set of Makefiles for your platform and then build all of the examples. This should work from a Linux shell, a Mac OS X Terminal, or a Cygwin shell on Windows (when using Cygwin, you should use Cygwin’s /usr/bin/cmake version of CMake).

% cd <source-code-root-dir>
% mkdir build
% cd build
% cmake -G "Unix Makefiles" ..
% make

Note, you can also run the configure.sh script in the root directory to create the build directory and perform the cmake command for you.

Building With XCode on Mac OS X

If you prefer to use the XCode IDE on the Mac rather than compile from the Terminal, then you can simply do the following:

% cd <source-code-root-dir>
% mkdir build
% cd build
% cmake -G "Xcode" ..
% open APIBook.xcodeproj

You can then build, run, and debug all of the examples from within XCode.

Build With Visual Studio on Windows

If you’re on Windows then you can configure and build the examples using Visual Studio as follows:

  1. Run the CMake GUI
  2. Specify the root directory of this package as the source location
  3. Create a build subdirectory and specify that as the build location
  4. Press the “Configure” button (you may have to press it twice)
  5. Press the “Generate” button

This should generate a Visual Studio solution file called APIBook.sln in the build directory that you specified. You can open that file in Visual Studio to build, run, and debug the examples.

Buy The Book On
Buy It on Amazon
Buy It On Elsevier

© 2024 Martin Reddy, All Rights Reserved