Navigation<> |
Compilation is handled by creating a control file, traditionally called 'Makefile', listing the source files, compiler options and the exact circumstances under which programs should be recompiled. Typing 'make' at the command line then recompiles all the files that have changed since the last compilation thus avoiding recompiling every single file every single time whether it needs it or not. You may also run make from within Emacs or nedit which has the advantage that the editor will warn you about any unsaved changes to your C files. Basically, the makefile is the equivalent of the 'project' in XCode or other Integrated Development Environments (IDEs).
We've created a simple example (basically the world's worst "Hello, world" program) for you to download.
# For a simple project you need to specify four things: # 1. The name you would like your executable to be called TARGET = myprog # 2. A list of your C source files CFILES = main.c file2.c # 3. The flags you wish to use to compile with CFLAGS = -O0 -g -Wall # 4. Libraries you need (-lm is the maths library) LIBS = -lm
As mentioned above, Linux and Mac OS X share the same debugger (gdb). On the Mac, gdb has a user-friendly front-end inside XCode. On Linux you can run gdb from inside of Emacs (they were originally written by the same person) but it is probably easier to use one of the available front-ends:
Which you use will probably depend on which is installed on your machine. Whichever you chose, learn the basics of seeing the values of variables and setting breakpoints and watchpoints. It's usually a combination of an item from a menu called "View" and right-clicking on a code statement or variable displayed in a window although some front-ends require you to do it within a specific window.