2

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!

1
  • When the error message is “ld: library 'fftw3' not found”, that is ld telling you there is a problem. It is not clang telling you there is a problem. ld is the linker. Commented May 22 at 2:16

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

intel macs used /usr/local for homebrew stuff. Apple silicon uses /opt/homebrew
@RichardBarber: Thanks, updated. Still a bit puzzling; OP would not have fftw3.h in /usr/local from Homebrew unless they installed fftw previously on an Intel Mac and migrated to their M2. Yet they appear to be using FFTW for the first time. (And I do not know whether Migration Assistant migrates things in /usr/local.)
That fixed it. Thanks, not familiar with this stuff yet ^^ As for the file in /usr/local/include, I guess it might be because I tried to install fftw using the configure file and makefiles before? I got errors doing that hence why I switched to brew, but I guess I didn't clean up my installation attempt properly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.