I have a Makefile that I use to build executable on mac os x, using mpicc compiler, linking mkl_lapack.h library.
Now this Makefile is perfectly working, the only problem is that I don’t know what to add if I want to compile Eigenvalues.c linking other .c files, if I want to link myfile.c where do I have to write it in Makefile?
MKL_INCLUDE=/opt/intel/mkl/include
MKLROOT=/opt/intel/mkl/lib
CC = mpicc
LD = mpicc
IFLAGS = -I$(MKL_INCLUDE)
CFLAGS = -Wall -O2 $(IFLAGS) -std=c99
LFLAGS = $(MKLROOT)/libmkl_intel_lp64.a $(MKLROOT)/libmkl_sequential.a $(MKLROOT)/libmkl_core.a -lpthread -lm
PROGRAMS = Eigenvalues
all: $(PROGRAMS)
Eigenvalues:
$(CC) $(CFLAGS) -o $@ $^ $(LFLAGS)
%.o: %.c
@echo C compiling $@
$(CC) -c $(CFLAGS) -o $@ $<
clean:
rm -rf *.o $(PROGRAMS)
Eigenvalues: Eigenvalues.c
Simply have the
Eigenvaluestarget depend on all the.ofiles (not the.cfiles, as you have!) that make up the application. Conventionally, the list of these objects is put in a variable:By the way, since you are using the standard variable names
$(CC)and$(CFLAGS), you can leave out the%.o: %.crule entirely; Make has a built-in rule that does the same thing.