background preloader

Computer

Facebook Twitter

Compiling and Linking. When programmers talk about creating programs, they often say, "it compiles fine" or, when asked if the program works, "let's compile it and see". This colloquial usage might later be a source of confusion for new programmers. Compiling isn't quite the same as creating an executable file!

Instead, creating an executable is a multistage process divided into two components: compilation and linking. In reality, even if a program "compiles fine" it might not actually work because of errors during the linking phase. The total process of going from source code files to an executable might better be referred to as a build. Compilation Compilation refers to the processing of source code files (.c, .cc, or .cpp) and the creation of an 'object' file. Linking Linking refers to the creation of a single executable file from multiple object files. You might ask why there are separate compilation and linking steps. CS 11: Compiling C programs. It is important to understand that while some computer languages (e.g.

Scheme or Basic) are normally used with an interactive interpreter (where you type in commands that are immediately executed), C doesn't work that way. C source code files are always compiled into binary code by a program called a "compiler" and then executed. This is actually a multi-step process which we describe in some detail here.

The different kinds of files Compiling C programs requires you to work with four kinds of files: Regular source code files. There are other kinds of files as well, notably libraries (".a" files) and shared libraries (".so" files), but you won't normally need to deal with them directly. The preprocessor Before the C compiler starts compiling a source code file, the file is processed by a preprocessor. Preprocessor commands start with the pound sign ("#"). #define. There are a number of other preprocessor commands as well, but we will deal with them as we need them. % gcc -c foo.c References. Language Reference. Index of /gnu/doc/html. Open Book - Managing Projects with GNU make, 3rd Edition.