This document is part of the HTML publication "An Introduction to the Imperative Part of C++"

The original version was produced by Rob Miller at Imperial College London, September 1996.

Version 1.1 (modified by David Clark at Imperial College London, September 1997)

Version 1.2 (modified by Bob White at Imperial College London, September 1998)

Version 1.3, 1.4, 2.0, ..., 2.18 (modified by William Knottenbelt at Imperial College London, September 1999-September 2019)

Appendix 1 - Guide to emacs and g++

Using emacs and g++ to create and run a simple C++ program

This tutorial shows you how to create, compile and execute a simple "hello_world" C++ program using the emacs editor and the g++ compiler.

Step One - Create a new directory/folder

It is recommended that you create a new folder for each program that you wish to write.

Step Two - Create the program files

Should you wish to quit emacs you can do so with Ctrl-x Ctrl-c, but in fact everything you need to do to run your program can be done from inside emacs so this is not necessary.

Step Three - Create a Makefile

A "makefile" is a set of rules for compiling a program for use by the Unix utility make. The interpretation of this particular makefile is that the target of the compilation is an executable file called hello_world. hello_world depends on the file hello_world.cpp, such that whenever hello_world.cpp is altered, hello_world should be remade. The command for remaking hello_world from hello_world.cpp using the g++ compiler is given in the second line. Here the -Wall option turns all warnings on, -g includes debug information and -o hello_world tells the compiler to put the executable program in a file called hello_world. For more information about target directed compilation using make click here.

Step Four - Compile the program and prepare the executable

Step Five - run the executable program