简体   繁体   中英

Using FFTW3 Fortran library in MacOS

I am getting the following error while trying to compile a Fortran program with gfortran and FFTW3 library. The program however compiles successfully with the Intel compiler ifort.

Error

Undefined symbols for architecture x86_64:
  "__gfortran_os_error_at", referenced from:
      _MAIN__ in ccAVlghr.o
ld: symbol(s) not found for architecture x86_64

Compile Command

gfortran -I/usr/local/include -L/usr/local/lib pois.f90 -lfftw3 -lm

pois.f90 is the program which contains FFTW3 commands to solve a Poisson equation through Fourier transform.

The equivalent C program also compiles and executes successfully. The FFTW3 statements are inserted in Poisson.f90 as per FFTW3 documents. The routine which uses FFTW3 commands is given below

subroutine fft_forward(j,f,Fr,Fi)
  use, intrinsic :: iso_c_binding
  implicit none
  include 'fftw3.f03'
  double precision :: f(j),Fr(j),Fi(j)
  integer :: i,j
  type(C_PTR) :: plan
  complex(C_DOUBLE_COMPLEX) :: FF(j)

  plan = fftw_plan_dft_r2c_1d(j,f,FF,FFTW_ESTIMATE)
  call fftw_execute_dft_r2c(plan,f,FF)
  call fftw_destroy_plan(plan)

  do i = 1,j
    Fr(i) = real(FF(i))/j
    Fi(i) = aimag(FF(i))/j
  enddo

  Fr = Fr/j; Fi = Fi/j
end

I also tried using a compiler flag -lgfortran but got the same error. Any suggestion will be of great help.

It probably depends on what you did while installing GNU Fortran , FFTW , et al.

In my case, it works as expected.

I have GNU Fortran installed from sources: gcc-9-2-0

Then, I have built FFTW using my own installation of GNU Fortran

./configure --prefix=$HOME/opt/usr/local/fftw/fftw-3.3.10 CC=gcc-9.2.0 MPICC=mpicc F77=gfortran-9.2.0
make
make install

and then, I have compiled your sample using

gfortran-9.2.0 -I$HOME/opt/usr/local/fftw/fftw-3.3.10/include -L$HOME/opt/usr/local/fftw/fftw-3.3.10/lib -lfftw3 -lm -c simple.f90

I have also added short _main stuff like so to double check it links with the stuff

program main

   print *, 'Hello'

end program main

after building, it runs as expected

gfortran-9.2.0 -I$HOME/opt/usr/local/fftw/fftw-3.3.10/include -L$HOME/opt/usr/local/fftw/fftw-3.3.10/lib -lfftw3 -lm simple.f90 -o main
./main
 Hello

I guess you have sort of a messy GNU Fortran + FFTW installation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM