C++ Primer For Java Programmers

Program Compilation

Linked Lists Table of Contents Preprocessor Directives
Compilation and execution of a C++ program depends on the platform or operating system. The following description refers to command-line compilation and execution on UNIX based systems using the GNU family of compilers.

Compiling and Linking

Creating an executable C++ program involves both compilation and linking. For simple programs consisting of a single source file, the compilation and linking can be combined with the following command (assuming the source file is in the current working directory)

g++ -o mypgm mypgm.cc

The -o option specifies the name of the executable program created from compiling and linking the source file mypgm.cc


Be very careful using this command. It is not unusual to accidentally enter something similar to

    g++ -o mypgm.cc mypgm.cc

instead of that specified above. If you make this mistake, there will be no warning and the compiler will create the executable named mypgm.cc which overwrites your sourcefile.


If you the program to be executed is in the current working directory, then simply enter the following, where mypgm is the name of your executable program


Linked Lists Table of Contents Preprocessor Directives

Print - Changes - Search
Last modified: April 27, 2007, at 02:20 PM.