HOWTO: Create and compile programs on UNIX

  1. Telnet to either cssun.georgetown.edu or gusun.georgetown.edu by performing the following steps:

    1. From a Windows machine on the campus network, click on the Start menu and select the Run option.

    2. In the dialog box type: telnet gusun.georgetown.edu Or type: telnet cssun.georgetown.edu, depending on where you have an account.

    3. At the login prompt enter you userid and hit enter or return.

    4. Then type your password and hit enter or return.

    5. You should see a prompt that looks like gusun% or cssun% once you have successfully logged onto the system.

  2. To create a program on UNIX, perform the following steps:

    1. Open up an editor and create a program. To use the pico editor type: pico <program name> (e.g., pico first.cc).

    2. To get help in pico, type ^G, meaning hold down the Control key and press "G".

    3. To use the vi editor type: vi <program name> (e.g., vi first.cc).

    4. To get help for vi, at the UNIX prompt, type "man vi", which will display the on-line help file for vi. program using vi.

    5. As an example, type: pico first.cc

    6. This will open an empty file named first.cc. Start typing and enter the following program:
      // A first C++ program that sums two numbers.
      
      #include <iostream>
      
      using namespace std;
      
      int main()
      {
        int x, y, sum;
      
        y = 5;
        x = 6;
        sum = x + y;
        cout << "The sum is " << sum << endl;
        return 0;
      } // main
      
    7. Once you have entered the program, press ^O to save your file and ^X to exit pico.

    8. NOTE: If you're a CS major, we strongly suggest that you learn and use the vi editor.

  3. To compile a program under UNIX, perform the following steps:

    1. Type: g++ first.cc

    2. If there are errors in your program, then they would be displayed, and you'll need to edit the program and fix the errors.

    3. If you entered the program correctly, then you will be returned to the UNIX prompt.

    4. The compiler creates an executable file called "a.out", which is the default name for executables.

    5. To run the program simply type "a.out" at the UNIX prompt.

    6. The program should produce the output:
        The sum is 11
        
    7. You can rename the executable by typing "mv a.out first.exe", which renames a.out to first.exe.

    8. You can also specify the desired name of the executable at compile time by typing: g++ -o first.exe first.cc

  4. If you plan to use a C++ compiler on a Windows machine or on a Mac, then you'll need to upload the file to gusun or to cssun using the ftp program. (ftp stands for "File Transfer Program.") On a Windows machine, perform the following steps:

    1. On your Windows machine, click the Start button, and select the Run menu option.

    2. In the dialog box, type: ftp gusun.georgetown.edu

    3. Enter your userid and password.

    4. Use the command "lcd", which stands for "local change directory", to navigate to the directory that contains your source file.

    5. If your source is on a floppy disk, then you type "lcd a:".

    6. If your source is in a directory, then you type, say, "lcd c:\borland".

    7. Once you're in the same directory, to transfer the file, type "put <filename>" (e.g., put first.cc).

    8. To leave the ftp program, type "bye".

    9. There is a transcript of an ftp session on the COSC-071 Frequently Asked Questions List.