Use a Makefile eat this:
CC=gcc
CFLAGS=-g
LDFLAGS=-g -pthread
DEPS = func.h
OBJ = main.o func.o
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS
miprog: $(OBJ)
gcc -o $@ $^ $(LDFLAGS)
The previous makefile assumes that you have three files:
main.c
func.c
func.h
If you have more or fewer files, adjust it appropriately.
The .h have to put them in DEPS
.
For each .c you have to put a .o in OBJ since they are first compiled and then linked.
In CFLAGS
put the options you use to compile. For example -g if you do debugging.
In LDFLAGS
you set the linking options. In this case -lpthread.
And in CC
you put the compiler that you use.
Put this file called Makefile in the same directory as your source code. And to compile it, just execute:
make