Search code examples
cpathheader-filesgfortranfftw

Can not find fftw3.h even after adding them to PATH


Basis

I have installed FFTW in my system manually by using ./configure, make commands the procedure mentioned in the website using some flags.

I do thus have fftw3.h header file as can be seen below

locate fftw3.h
/home/anirbankopty/Softwares/FFTW/fftw-3.3.10/api/fftw3.h
/home/anirbankopty/Softwares/FFTW/fftw-install/include/fftw3.h

Problem

But, still, when compiling my C code using the -lfftw3 flag, it says

gcc FFT_denoise.c -lfftw3 -lm
FFT_denoise.c:5:10: fatal error: fftw3.h: No such file or directory
    5 | #include <fftw3.h>
      |          ^~~~~~~~~
compilation terminated.

I tried doing in Fortran and also there I am getting

gfortran FFT_denoise.f03 -lfftw3 -lm
/usr/bin/ld: cannot find -lfftw3
collect2: error: ld returned 1 exit status

Tried

I Tried adding those fftw3.h path i.e. /home/anirbankopty/Softwares/FFTW/fftw-install/include/ to the PATH variable, but still the problem persists.

I use zsh shell.


Solution

  • The path to included files belongs in the -I argument to the compiler, not in PATH:

    gcc -I/home/anirbankopty/Softwares/FFTW/fftw-install/include/ FFT_denoise.c -lfftw3 -lm
    

    Similarly the path to library files belongs in the -L argument. This will probably the next issue you will face.