Domanda

So I am using FFTW 3.3.3. While trying to invoke make from the Makefile, I encounter this problem:

    /usr/bin/ld: cannot find -lfftw3
    collect2: ld returned 1 exit status
    make: *** [fftw_ex] Error 1

I previously compiled my code directly with:

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

and it worked just fine. Here is my Makefile, in case it's needed:

    #                     RULES
    EXEC := fftw_ex
    SRC := $(wildcard *.c)
    OBJ := $(SRC)
    #                     OPERATIONS
    CC := gcc
    CFLAGS := -O3 -I$TACC_FFTW3_INC
    LDFLAGS := -L$TACC_FFTW3_LI
    LDLIBS := -lfftw3

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

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

    #                   PHONY TARGETS
    .PHONY: clean

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

Any help would be greatly appreciated!

È stato utile?

Soluzione

Running make should show you the commands it runs, so you can compare that to the command you run by hand. But this

  $(CC) $(LDFLAGS) $(LDLIBS) -g -o $@ $^

Should rather make the libraries to link in come after the files to compile:

   $(CC) -g -o $@ $^ $(LDFLAGS) $(LDLIBS) 

You can't use $VARIABLE_NAME in a makefile for shell variables, the syntax in a makefile is $(VARIABLE_NAME), so

CFLAGS := -O3 -I$(TACC_FFTW3_INC)
LDFLAGS := -L$(TACC_FFTW3_LIB)

Make sure the TACC_FFTW3_LIB and TACC_FFTW3_INC are exported from the shell too. (Note that you spelled TACC_FFTW3_LI wrong)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top