1

I am on macOS Catalina (10.15.5) and I have installed FFTW using brew install fftw. I also have GCC (version 10.2.0) installed which is symlinked to the commands I am using below.

I am able to compile and run a simple C++ program like so:

g++-10 test.cpp -L/usr/local/lib -I/usr/local/include -lfftw3 -lm 

But, I had to modify the environment variable CPATH to make this work.

I am unable to get a simple Fortran FFTW example to work (I am using this one). The command I am using to compile is:

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

The error I get is as follows:

Undefined symbols for architecture x86_64:
  "__gfortran_os_error_at", referenced from:
      _MAIN__ in ccRvJaEQ.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

If I understand correctly, the linking step fails. Any inputs on how I might find the relevant paths that I may have to pass to the compiler would be very helpful. I searched for solutions and I wasn't able to find one. But, in case I missed something obvious, I apologise.

Mythreyi
  • 121
  • 1
  • 5
  • Do you have fftw3 Fortran library installed? I am not mac user so do not know the technical stuff, but at least usually the libraries have to be language specific. In my mind, one cannot use library meant for C or C++ for Fortran... – msi_gerva Aug 18 '20 at 12:45
  • @msi_gerva Good point, but yes, FFTW functions can be called from Fortran and I have the required files. I think that's why the compiling step doesn't seem to have caused any problems. So, I think that's not the issue here. – Mythreyi Aug 18 '20 at 12:53
  • Perhaps you can try with your own installed version - http://www.fftw.org/download.html? To make sure that the library is built with the same version of compiler... – msi_gerva Aug 18 '20 at 14:05
  • Okay, that makes sense. Thanks. I will try that. – Mythreyi Aug 18 '20 at 18:16
  • @msi_gerva I compiled FFTW on my own, but the issue persists! – Mythreyi Aug 19 '20 at 05:27
  • For me everything works, I was able also to run command (compile your testcase): `gfortran -o test.x test.f90 -L/nobackup/opt/gfortran/9.3.0/fftw-install_3.3.8/lib -I/nobackup/opt/gfortran/9.3.0/fftw-install_3.3.8/include -lfftw3 -lm` . The /nobackup/... was the location, where I installed the library. In addition, take a look at this post: https://stackoverflow.com/questions/19821041/g-ld-symbols-not-found-for-architecture-x86-64. Is it possible that you are mixing 32bit and 64bit libraries? – msi_gerva Aug 19 '20 at 06:21
  • I compiled FFTW to a custom directory now, and the compilation for the Fortran test case works. Perhaps I need to remove past instances of FFTW files in the default paths to avoid possible mixing up 32bit and 64bit libraries? Thanks for your help @msi_gerva! – Mythreyi Aug 19 '20 at 08:25

1 Answers1

1

Thanks to msi_gerva's helpful hints through comments, I was able to solve the issue by downloading FFTW and compiling it to a custom directory following the installation directions.

Now, the linking doesn't fail if I pass the new locations of the libraries to gfortran like so:

gfortran-10 test.f90 -L/new/path/to/lib -I/new/path/to/include -lfftw3 -lm

Since /usr/local/ is the default installation path, it's possible that there is a mixing up of the FFTW library files from previous installations.

Mythreyi
  • 121
  • 1
  • 5