Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

HOW TO COMPILE YOUR Ansi-C IN THE UNIVERSITY MAIN FRAME

First log in to unixlab.sfsu.edu. Then create your programming logic and at last in order
for you to compile your Ansi C program, you must type the following command:
gcc lm filename.c

<CR>

The above command will compile your Ansi C program on our university main frame and
if no errors it will put the executable file into ./a.out.
Here are the instructions from the web page I sent you the link to. If you look at step
five or step six you will see that you need to specify an output file name using the "o" switch. Using your example your command needs to be:

gcc -o myexecutible filename.c


This should compile filename.c and create an executable file named "myexecutible".

1. Open up a terminal window.


2. Type "gcc --version" into the terminal. If the command is not found, it is likely that
GCC isn't installed.
3. Install GCC if needed, by referring to the GCC website installation procedures at
http://gcc.gnu.org/install/ (This takes some familiarity with linux which is not covered
in this article)
4. Go to the directory where your .c program files are located.
5. To compile a single source file, type: gcc -o output file file1.c
6. To compile multiple files, type: gcc -o outputfile file1.c file2.c file3.c
7. To compile with more error checking using the -Wall tag: gcc -Wall -o outputfile
file1.c
8. To compile files without linking them type: gcc -c file1.c file2.c file3.c
9. After the last step, if you want to link them, type: gcc -o outputfile file1.o file2.o
file3.o
10. Fix any errors/warnings the compiler reports.
11. Recompile the code if you had to fix errors.
12. Repeat step 10-11 until the program builds successfully.
13. Execute the program.
You can skip steps two and three since we know that gcc is installed and available on
unixlab.

You might also like