Main Content

Turning C from source to a running program

Archive - Originally posted on "The Horse's Mouth" - 2006-10-06 05:20:13 - Graham Ellis

With scripting languages (or near-scripting languages) such as shell, Tcl, Perl, Python and PHP, the developer just edits a file of program code, and tests it - the tools that he uses roll the translation of his source into something that can be run without him having to make further inputs. C is somewhat different .... to here's how to convert a C program from source to executable.

1. Enter your source code (a file extension .c is common).

2. Compile into an object file (extension .o or .obj). This is a binary file that contains machine code for the machine that you'll be running on, but it's not yet a complete program - it's a program component. In effect, your compiling has turned a raw potato into a roasted one, but it's still not a complete meal.

3. Link / Load / Taskbuild your .o or .obj files; that joins them together into a single conglomorate executable file, and brings in standard library files too, so that the file as a whole can be run. You have now added your Roast Beef, Yorkshire Pudding, and brussel sprouts and made up a complete course.

* The COMPILER will initally run the C pre-processor which will act on lines starting with a # character, allowing for other files to be included, constants defined, and selective debug code / system dependent code to be included as appropriate.

* The whole process of one or more compiles followed by a link may be defined in a makefile. The Makefile defines the commands necessary for each step of the process, and also lets you define which file depends on whihch other file - the net effect of this is to enable the compiler to skip over files that haven't been changed since you last did a compile by looking at the timestamp on the .c file in relation to the timestamp on the .o; very clever - I remember back to "pre-make" days and running compiles and loads of a big CAD system I wrote that took nearly an hour to process!