1

I try to use the fftw3 library in Fortran. I get an undefined reference error when calling the planner subroutine.

As I am neither proficient in Fortran nor C, all I tried so far was re-reading the documentation and hoping to stumble over the solution. Neither the reading nor the stumbling were successful so far.

I work on ubuntu and use gfortran.

gfortran dft.f90 fftw3.f90 dft_variable.f90 -L/usr/lib/x86_64-linux-gnu -libfftw3

dft.f90 is the main program.

fftw3.f90 contains the fftw3 constants. They are found here: https://people.sc.fsu.edu/~jburkardt/f_src/fftw3/fftw3.f90

dft_variables.f90 contains some variables and parameters I need for the dft code.


        Program simple_dft

        use fftw3
        use dft_variable

        Implicit none

          real, dimension(:),allocatable :: fft_in, fft_out, rho
          integer*8 :: plan,
          integer :: num_points

          {...} ! Here happens the calculation of the initial density rho

          allocate(fft_in(num_pts),fft_out(num_pts),rho(num_pts))

          fft_in = rho

          call dfftw_plan_dft_r2c_1d(plan,num_pts,fft_in,fft_out,FFTW_ESTIMATE)
          call dfftw_execute_dft(plan, fft_in,fft_out)

        End Program simple_dft

I expected the planner to create the plan necessary to calculate the FFT of rho.

_variable.f90 -L/usr/lib/x86_64-linux-gnu-libfftw3
/tmp/cc8nDlG7.o: In function `MAIN__':
dft.f90:(.text+0x3aeb): undefined reference to `dfftw_plan_dft_r2c_1d_'
dft.f90:(.text+0x3b0d): undefined reference to `dfftw_execute_dft_'
collect2: error: ld returned 1 exit status
Aurel
  • 11
  • 2
  • I added the tag `fortran`, it's more widely viewed than `fortran90`. – High Performance Mark Jun 12 '19 at 08:13
  • The linked question is about other libraries, but the same principle holds: you need to say which library to use (`-lfftw` say) as well as where to find it (the `-L` flag). – francescalus Jun 12 '19 at 08:29
  • Isn't that what I am doing with "-L/usr/lib/x86_64-linux-gnu-libfftw3"? – Aurel Jun 12 '19 at 08:40
  • No, that is only saying where to look for libraries. See also the many answers in https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix Although it is for C++, the options for all GCC compilers are similar. – Vladimir F Героям слава Jun 12 '19 at 08:45
  • I found a missing space in that line. It should be "-L/usr/lib/x86_64-linux-gnu -libfftw3". That leads to the error "cannot find -libfftw3" even though "locate libfftw3" finds it in that path. – Aurel Jun 12 '19 at 08:45
  • Please do read it first, really. Not just skim through, read. You will find out that -lib becomes -l. – Vladimir F Героям слава Jun 12 '19 at 08:46
  • Thank very kindly. Even reading it, I have missed the last part. I was not aware that the compiler needs a different name than the actual name. You saved my day, good sir. – Aurel Jun 12 '19 at 08:52

0 Answers0