next up previous
Next: Explanation of the Program Up: A first C++ program: Previous: A first C++ program:

What is Compiling and Linking?

The file hello.cc is called a C++ ``source'' code file. It is supposed to be human readable. The computer, on the other hand, expects a correct sequence of binary 0's and 1's for its instructions. The machine language instructions are found in a file called the ``executable''. It isn't human readable. In the above example, that file is called hello. The compiler translates the source code into an executable. It does this in two steps, although in the above example, the two steps are combined. It first translates the code in each source file (here there is only one) into an intermediate ``object'' file. If we had done this as a separate step we would have seen a file hello.o appear in the compilation directory. Next, the object files are linked (combined) with code selected from the compiler's standard libraries to create the executable. In the above example those standard library files include instructions needed for making text appear on the console.

To make the program run, you type the name of the executable in the xterm window, as if it were a Unix command. Since it isn't a standard command, if you want to execute the program in a directory other than the compilation directory, you must include the path to the file.


next up previous
Next: Explanation of the Program Up: A first C++ program: Previous: A first C++ program:
Carleton DeTar 2007-08-17