Compiling C consits of several steps:
Using make
bid19628:startup ltoma$ make
bid19628:startup ltoma$ cat Makefile all: hello.c gcc -g -Wall -o hello hello.c clean: $(RM) hello bid19628:startup ltoma$ make gcc -g -Wall -o hello hello.c bid19628:startup ltoma$A more generic version:
# the compiler: gcc for C program, define as g++ for C++ CC = gcc # compiler flags: # -g adds debugging information to the executable file # -Wall turns on most, but not all, compiler warnings CFLAGS = -g -Wall # the build target executable: TARGET = hello all: $(TARGET) $(TARGET): $(TARGET).c $(CC) $(CFLAGS) -o $(TARGET) $(TARGET).c clean: $(RM) $(TARGET)And an example of building several executable from multiple .o files:
PROGRAMS = blockit visblocks DEFAULT: $(PROGRAMS) CC = gcc -std=c99 CFLAGS = -m64 -Winline -g -DNDEBUG -O3 -Wall LIBS = -lm blockit: blockit.o blgrid.o rtimer.o $(CC) -o $@ blockit.o blgrid.o rtimer.o $(LIBS) visblocks: visblocks.o blgrid.o rtimer.o visblgrid.o $(CC) -o $@ visblocks.o blgrid.o rtimer.o visblgrid.o $(LIBS) blockit.o: blockit.c blgrid.h rtimer.h $(CC) $(CFLAGS) -c blockit.c -o blockit.o blgrid.o: blgrid.c blgrid.h $(CC) $(CFLAGS) -c blgrid.c -o blgrid.o rtimer.o: rtimer.c rtimer.h $(CC) $(CFLAGS) -c rtimer.c -o rtimer.o visblocks.o: visblocks.c blgrid.h rtimer.h $(CC) $(CLFAGS) -c visblocks.c -o visblocks.o visblgrid.o: visblgrid.c visblgrid.h blgrid.h $(CC) $(CLFAGS) -c visblgrid.c -o visblgrid.o clean: rm -f *.o blockit visblocks