next up previous contents
Next: WWW The World Wide Up: Finding Your Way Around Previous: Electronic Mail   Contents

Compiling Programs

To compile a C++ program on a Unix system you can use either of the following methods:

  1. g++ filename.cc

  2. g++ -o exec-name filename.cc

filename.cc is your C++ program created with an editor like vi, pico, or emacs. exec-name is the name of the executable file, and g++ is the name of the C++ compiler.

In the first case the C++ compiler will create the executable file with default name a.out. In the second case you can state the name of executable file by substituting exec-name with a name you wish to have.

If the compilation produces no errors, you can run your program by typing your exec-name or a.out. One warning, don't call your program test. The command test is built into the shell and will be executed before your command.

If the program compiles correctly but will not run:

% a.out
a.out: Command not found.

check your PATH environment variable. Some Unix systems (like RedHat) do not put the current directory in the default path. You can get around this by typing ./a.out or by adding . to your path.


next up previous contents
Next: WWW The World Wide Up: Finding Your Way Around Previous: Electronic Mail   Contents
WWW Data 2003-03-07