Search code examples
bashcompilationfortranfftw

compile FFTW fortran program


I'm quite new to Unix and bash systems, therefore i'm sorry in advance if the question might look stupid.

I've recently downloaded and installed the FFTW program on my iMac (following the guidelines in chapter 10 of http://www.fftw.org/fftw3.pdf). The installation has succeeded as i get no error when i do "make check".

Now i wanted to start writing a small test program using the above mentioned libraries.

The fortran code is very simple (and it is basically just a check of how to link the FFTW libraries to fortran):

program fft

use, intrinsic :: iso_c_binding
include 'fftw3.f03'

implicit none

end program fft

however when it comes to compile the program i'm completely clueless (basically because i'm not expert at all in compiling) what i typically do to compile is:

gfortran -o "executable_ename"  "main.f90"

However this is not working, in particular i get the following error:

 fft.f90:4: Error: Can't open included file 'fftw3.f03'

If you could give me a hand with this problem, and maybe also explain what i'm missing and why it would be great.


Solution

  • You need to specify where fftw3.f03 is located! On my machine, it is in /usr/include, so I use:

    gfortran -I/usr/include -o "executable_ename" main.f90
    

    BTW: the implicit none must go in front of the include:

    program fft
      use, intrinsic :: iso_c_binding
      implicit none
    
      include 'fftw3.f03'
    end program fft