delorie.com/djgpp/doc/ug/basics/compiling.html | search |
Being of a Unix origin, GCC has a somewhat different flavor of command-line syntax and its peculiar compilation and link algorithms. It also has a plethora of optional switches, some of them obscure or semi-documented. These are known to confuse users, especially those who had previous experience with DOS-based C compilers.
As GCC is a compiler, it's primary purpose is to convert source code that you write into programs the computer can run. To do this, it has many resources it calls upon. First and foremost, it reads your source files. Based on the file extension that you gave your program, it selects the appropriate commands it needs to run to turn the source you gave it into the output file you specified. Remember, gcc is primarily a Unix compiler, so it assumes that the file names you are giving it are case sensitive! Here is a list of file extensions and what gcc does with them.
Here's a summary of what gcc does for you:
You probably noticed that gcc can produce a number of different types of output files as well. The -E, -S, and -c options tell gcc to stop the process at the indicated point and produce output. Note: Output from the -E option is printed to the screen, unlike the other options that save the output in a file. You can redirect the output to a file if you want.
If you don't specify any output options, by default gcc creates an output file called a.exe. This is different from most dos compilers, which name the program after the first source or object it finds. You may specify an alternate output file with the -o option (which also works in conjunction with -c or -S), like this:
The above example is also the simplest way to compile a C source file into a dos executable. If your program consists of multiple sources, you can compile them all at once:
You can also compile each separately and link them into a program:
Separate compilation is faster when you're debugging your program, because you only have to recompile the sources that you modify. When you use make to manage your project, it keeps track of this for you and only recompiles the modules you need.
webmaster | delorie software privacy |
Copyright © 1997 | Updated Apr 1997 |