Question

So I can compile my code (fftw_ex.c) directly with:

    login$ gcc -o -g fftw_ex fftw_ex.c -I$TACC_FFTW3_INC -L$TACC_FFTW3_LIB -lfftw3

However, my professor prefers that we use a Makefile. I am just learning how to use Makefile and make, and I'm having trouble creating the Makefile. So far, this is what I have:

    #                     RULES

    EXEC := fftw_ex
    SRC := $(wildcard *.c)
    OBJ := $(patsubst %.c,%.o,%(SRC))

    #                     OPERATIONS

    CC := gcc
    CFLAGS := -O3 -I$TACC_FFTW3_INC
    LDFLAGS := -L$TACC_FFTW3_LIB
    LDLIBS := -lfftw3

    $(EXEC): $(OBJ)
            $(CC) $(LDFLAGS) $(LDLIBS) -o -g $@ $^

    %.o: %.c
            $(CC) $(CFLAGS) -c $<

    #                   PHONY TARGETS

    .PHONY: clean

    clean:
            @echo Cleaning...;rm -rf *.o fftw_ex

I know there's a problem with the SRC line, as i'm getting the error message:

    make: *** No rule to make target `%(SRC)', needed by `fftw_ex'.  Stop.

Any help to get this to work would be appreciated.

Was it helpful?

Solution

1)To resolve: No rule to make target `%(SRC)' replace %(SRC) in OBJ := $(patsubst %.c,%.o,%(SRC)) with $(SRC)

2)In line: $(CC) $(LDFLAGS) $(LDLIBS) -o -g $@ $^

you have mistake: -o -g, should be -g -o

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top