- Create a folder "hello-world" using mkdir
- Create an empty file "hello-world.c" using touch
mkdir hello-world
cd hello-world
touch hello-world.c
Fill in the following content into hello-world.c
#include <stdio.h>
int main() {
printf("Hello World\n");
return 0;
}
gcc -o hello-world hello-world.c
./hello-world
all: hello-world
hello-world: hello-world.o
gcc -o $@ $<
%.o: %.c
gcc -c -o $@ $<
clean:
@rm -f *.o
@rm -f hello-world
SRCS = \
hello-world.c
OBJS=${SRCS:.c=.o}
all: hello-world
hello-world: $(OBJS)
gcc -o $@ $<
%.o: %.c
gcc -c -o $@ $<
clean:
@rm -f $(OBJS)
@rm -f hello-world
CFLAGS=-Wall =ggdb
SRCS = \
hello-world.c
OBJS=${SRCS:.c=.o}
all: hello-world
hello-world: $(OBJS)
gcc -o $@ $<
%.o: %.c
gcc $(CFLAGS) -c -o $@ $<
clean:
@rm -f $(OBJS)
@rm -f hello-world