While editing any file in the program directory (such as echo.cpp in the previous example), issue the command M-x compile <Enter>.9You will be prompted for the make command to use. The default is make -k, which is a good choice (the -k option means to continue compiling in the presence of errors). If the compile has errors or warnings, you can use the command C-x ` to jump to the next error, automatically opening an emacs buffer scrolled to the offending line of code (very convenient!).
Some c-mode environments in emacs bind C-c C-c to this command (two successive control-c keystrokes). To define that in your own .emacs file, the following line can be added:
(global-set-key "\C-c\C-c" 'compile) ; formerly undef (text-mode)
The emacs text editor has many conveniences for software development. This section describes a few of them. The next appendix discusses debugging STK programs with gdb. In particular, §K will describe debugging your program using gdb from within emacs.
One of the nicest aspects of working with STK programs is that all source (C++) is available, facilitating debugging. Single-stepping someone else's STK program is a very good way to learn how it works. Object oriented software is often hard to read because its functionality is spread out over many member functions in many class files, some of which may be in separate libraries. Single-stepping the code in a debugger solves this problem by showing you exactly what code is being executed and in a natural order, complete with the ability to inspect variables, stack frames, and even larger data structures such as arrays, structs, and objects.
On Windows platforms, development tools such as Microsoft Visual C++ provide all the debugging support you need.
On UNIX platforms, the standard C++ debugger is gdb, and we'll look at that case below.10