C++ Primer for Java Programmers

 

Program Compilation

Linked ListsCpp PrimerPreprocessor 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

Warning Warning

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.

Execution

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

./mypgm



Linked ListsCpp PrimerPreprocessor Directives
Print -- Recent Changes
Page last modified on April 27, 2007, at 02:20 PM