30Chapter2 • Working With Editors
2.2.6Compiling
Emacs has the facility to call external compilers, parse their output and display the results
in a buffer. As the results are displayed, the programmer can then move forward and backward
through any error or warnings. As each error or warning is displayed, the appropriate line in the
code is displayed and may be edited.
To invoke the compiler from Emacs, type
M-X compile
; in response, Emacs will ask
you for the command to use to compile the program for application. You can either specify
make
or the command line compiler with all the options. The default is to invoke
make
with the
–k option in order to continue as far into the
make
as it can when encountering errors.
For example, assume that the following (broken) bit of code is in a buffer entitled ‘main.c’.
#include
int main ()
{
printf(‘Hello World\n’);
}
The compiler may be invoked by typing:
M-X compile
Compile command: gcc –o main main.c
If the buffer being compiled has not been saved, the editor will prompt you to save it. The
results of the compilation will appear in the *compilation* buffer as seen in Figure 2-5.
Figure2-5 The results of M-X compile.
Next Page >>
<< Previous Page
Back to the Table of Contents