trying to get fftw to work.
I'm on an M2 macbook, used brew to install fftw. Within my IDE, #include <fftw3.h>
doesn't throw an error, and autocomplete correctly lists fftw constants and functions, so it seems like it installed somewhat correctly?
But trying to compile this tiny program:
#include <stdio.h>
#include <fftw3.h>
int main(void) {
fftw_complex* P = fftw_malloc(1);
printf("Hello world\n");
}
Leads to: ld: library 'fftw3' not found
.
That was with clang FFT.c -L/usr/local/include -lfftw3 -o FFT
Also tried clang FFT.c -I/usr/local/include -L/usr/local/include -lfftw3 -o FFT
And clang FFT.c -lfftw3 -o FFT
And clang FFT.c -o FFT
where expectedly it says symbol not found
I tried brew installing gcc-14 aswell, but it doesn't work at all, stating:
In file included from /opt/homebrew/Cellar/gcc/14.2.0_1/lib/gcc/current/gcc/aarch64-apple-darwin24/14/include-fixed/stdio.h:75,
from FFT.c:1:
/opt/homebrew/Cellar/gcc/14.2.0_1/lib/gcc/current/gcc/aarch64-apple-darwin24/14/include-fixed/_stdio.h:78:10: fatal error: sys/cdefs.h: No such file or directory
78 | #include <sys/cdefs.h>
| ^~~~~~~~~~~~~
compilation terminated.
Running locate fftw3.h
returns 3 locations:
/opt/homebrew/Cellar/fftw/3.3.10_2/include/fftw3.h
/opt/homebrew/include/fftw3.h
/usr/local/include/fftw3.h
But none of the directories here work when I put them in as -L.
Not sure what else to do here :( fftw3.h is definitely where I tell the compiler it is!
fftw3.h
is not a library file. It is a header file. You need to tell ld
where the library file is. It is not in /usr/local/include
; that is where headers are. The library is probably in the directory /opt/homebrew/lib
, with file name libfftw3.dylib
or another name starting with libfftw3.
. Use -L/opt/homebrew/lib -lfftw3
or directly /opt/homebrew/lib/libfftw3.dylib
.
I do not know why you have a file /usr/local/include/fftw3.h
; I do not think Homebrew on Apple Silicon (ARM) macOS puts files there by default. You should avoid using that one unless you know why it is there; stick to the one in /opt/homebrew/include
. If you have done something to install FFTW in /usr/local
, then maybe there is a libfftw3.dylib
in /usr/local/lib
. (Perhaps these things in /usr/local
are links to corresponding things in /opt/homebrew
, which you installed via some Homebrew option or command? Or did you install them some other way? You should figure out what is in your system and be clear about why it is there and whether you want it there.)