>

Compiling and Running C Programs with Modules

CS 1323 Honors, Fall 1996

To Compile a C Module

Issue the Unix command
gcc -ansi -c moduleName.c
where moduleName is the name of the module.
If the program conforms to the grammatical rules of C, this command will generate a file called moduleName.o that contains a version of your program translated into a form using the native operations of the platform. This file is known as the "object file" for the module.

To Build a Runnable Program

Issue the Unix command
gcc -lm module1Name.o module2Name.o ...
note: -lm is hyphen lower-case-el lower-case-em
where each module name is the name of one of the modules the program uses (one of which must contain a function called main).

If the program conforms to the grammatical rules of C, this command will generate a file called a.out that contains a version of your program translated into a form that the the operating system can run. This file is known as the "executable file" for the C program. You may want to give the a.out file another name, to keep it from getting overwritten when you build another runnable program:

mv a.out newName.out

To Run a Program Using an Executable File

Use the name of the executable file as if it were a Unix command.
For example:
a.out
runs the program generated by a command like
gcc -lm module1Name.o module2Name.o ...

Last Modified: