Editing, Compiling, and Executing a C++ Program on PCC-AIX

Creating/Editing

Use a text editor such as vi, emacs, pico, or whatever else you may prefer, to create the C++ source file. After you have typed in all of the program code, save the file with a .C extension (e.g. program1.C)

Compiling/Linking

After you have created and saved your C++ source file, you can compile it (translate it into machine code) by using the AIX C++ compiler. The AIX C++ compiler is called xlC. (That's lowercase X, lowercase L, uppercase C)

Type the following line to compile and link your C++ code. A file called a.out will be created. This is what you will typically do while working on the assignments for this class:

xlC filename.C

If your program has no errors in it, then the compiler will create a file called a.out. If you have errors, you must go back into the editor and fix the errors. When you have lots of errors and you want the details about the errors saved in a file, type:

	x1C -q source filename.C 

This will create a file called filename.lst. You can examine this file with your text editor or other UNIX utilities such as less, more, or cat.

If you just want to compile your program without linking, you would use the -c compiler switch (meaning "compile only, don't link"):

	x1C -c filename.C

For this class, you probably won't want to "turn off" the linking phase.

If you want to create an executable file with a name other than a.out, you would type this line:

	x1C -o exename filename.C

This will create an executable program called exename, instead of a.out.

Executing

If the compiling/linking phase was successful, you can run (execute) your program by typing a.out, or, if you used the -o compiler switch, you can just type the name of the executable file that you specified. At the UNIX prompt type:

	a.out

and that will run the program.

Back to Outline