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


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.

Step Four - Compile the program and prepare the executable

Step Five - run the executable program

(BACK TO COURSE CONTENTS)