120 likes | 257 Views
Compiling a C Program. Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click on Start , then Run , and then type the word telnet and press the Enter key. A window will open on your desktop. This is what it looks
E N D
Before we can begin we must open a telnet session to phobos. There are a number of ways to do this, but the easiest is to click on Start, then Run, and then type the word telnet and press the Enter key.
A window will open on your desktop. This is what it looks like using Win2000. Type open phobos.senecac.on.ca and then press the Enter key. The Win98/95 method is next.
When the telnet window opens in Win98/95, click on Connect and then RemoteSystem.
Type phobos.senecac.on.ca in the Text Box labeled Host Name, then click on Connect.
The procedure is the same from this point using either Win2000 or Win98/95. Enter your user name and then press Enter, and then enter your password and press Enter.
Once you have logged on to the system your cursor will be at the command prompt ($). We are going to use a program named nled to create our C source file. Type nled welcome.c at the command prompt and then press Enter.
The nled edit window opens in insertion mode. We can just start typing to enter text. Type the code for the C source file and then press the Escape key (Esc) and the x key at the same time to save your file and exit nled.
Your cursor will be back at the command prompt after nled closes. Type cc welcome.c and press Enter. phobos will pause for a moment while your file is compiled. When it is finished the command prompt will reappear. Type a.out to see the output of your C program.
What Happened? Our source code is a series of instructions that we want to have carried out. Our instructions must be translated in to a language that can be understood by a computer. When we type cc filename.c we are telling the computer we are using to compile our source file, using the C compiler, into an executable file that can be run to produce the desired result. Remember that when we are logged on to phobos using a telnet session that the source file and executable file reside on phobos. The executable file will only work on phobos. To create an executable file that will work on your local machine the source file would have to be compiled locally.
What Happened? The default name for an executable file on phobos is a.out. To give your C program another name you must tell the compiler at compile time. If we wanted to name our executable to be named welcome1 the command would be: cc welcome.c -o welcome1 The general format of the compile command is: cc source.c - produces a.out cc source.c -o outputname - produces outputname
Summary • Open a telnet session to phobos • Use nled to create a C source file • Use the cc command to create an executable file • The default name for the executable file on phobos is a.out • Run the executable file by typing its name at the command prompt