www.delorie.com/djgpp/doc/ug/compiling/sol.html   search  
Guide: Sources, Objects, and Libraries

Humans and Computers don't speak the same language, except in science fiction. There are many steps involved in converting the source files that you write into programs that the computer understands. This section will discuss the terminology that is used to describe the results of each of those stages.

The text files that you create, be they C or C++ or even assembler, are source files. They are the source of all that a program is made of. You create these in whatever text editor you are familiar with. Note that it's important to not use a word processor for this, since word processors usually store text in their own formats, and not in plain text. A popular editor among DJGPP programmers is emacs, so you'd use a command like this:

emacs hello.c

For most languages, the first thing that happens is that your source is converted into a simpler language called assembler. The purpose in doing this is to make it easier to add support for new languages, since each language compiler doesn't have to do all the work, just enough to convert its language into assembler. Still, assembler is just another source file. In this example, your source (hello.c) is translated into an assembler file (hello.s). Note that most programmers will not use this method, instead relying on gcc to do this step and the next in one operation.

gcc -S hello.c

The next step is to assemble the assembler sources into an object. This is a binary file that contains machine code that corresponds to the parts of the program in that source file. It also contains information about the data in your source and how to integrate that source with other sources. This is usually done by default when you compile any source.

gcc -c hello.s

To do both steps at once, simply specify the source directly:

gcc -c hello.c

Sometimes, when dealing with large projects or toolkits, it is convenient to group a number of objects together into a library. A library does not change the format of the objects, it merely collects them, much like a zip or tar file. In most cases, you can treat a library the same way you would treat an object. The ar command manages "archives", another name for libraries.

ar rvs mylib.a bye.o foo.o math.o grill.o

Once you have all your sources turned into objects or libraries, you can link them all together to create your program.

gcc hello.o mylib.a -o hello.exe

  webmaster     delorie software   privacy  
  Copyright 1997   by DJ Delorie     Updated Apr 1997