Search code examples
gfortranfftw

Problems linking FFTW with gfortran (symbol(s) not found for architecture x86_64)


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.


Solution

  • 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.