It's a linker error, so you need to link with the fftw3 library.
When I built FFTW3 a while back with MinGW, it created a
libfftw3.a file, which you need to link to.
When I built fftw, I believe I followed the same page you did -- the "Building FFTW 3 under MinGW" section. But I built it within the MSYS2 environment because I found that to be the least painful way to build most projects that expect *nix environments.
https://www.msys2.org/
Once msys2 is set up, I launch an msys2 terminal, make sure my path variable includes the /bin folder of where I have mingw installed (e.g.
...;/c/mingw/bin).
Once you can invoke make while in an msys2 terminal, you just do,
./configure {options...}
make
and then locate where it produced the .a file(s).
Here is a 'hello world' sort of program I made to test the library, probably mostly copied from some tutorial, I don't remember.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fftw3.h>
double abs(fftw_complex c)
{
return std::sqrt(c[0]*c[0] + c[1]*c[1]);
}
double bin_freq(size_t n, size_t N, double Fs)
{
return n * Fs / N;
}
int main()
{
fftw_complex *in, *out;
fftw_plan p;
const size_t N = 512;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
double Pi = 3.14159265358979323846;
double Fs = 44100.0;
double freq = 3000.0;
double T = 1.0 / Fs;
for (size_t i = 0; i < N; i++)
{
in[i][0] = std::cos(2 * Pi * freq * i * T);
in[i][1] = 0.0;
}
fftw_execute(p); /* repeat as needed */
std::cout << std::fixed;
std::cout << std::setprecision(2);
for (size_t i = 0; i < N; i++)
{
std::cout << bin_freq(i, N, Fs) << " Hz : " << abs(out[i]) << std::endl;
}
fftw_destroy_plan(p);
fftw_free(in);
fftw_free(out);
}
|
I have {fftw-3.3.7 path}/api as an additional include directory and {fftw-3.3.7 path}/.libs/libfftw3.a as an object I'm linking with.
Note that my method of just trying to call make while under msys2 might not work for all libraries, for example zlib has been a total pain in the ass to compile in my personal experience, so I'm probably doing something wrong. It almost makes me want to just completely switch to Linux for developing various applications...
________________________________________________________
I haven't used VS Code as an IDE/editor. If you're still having trouble, I could probably try to a clean install of fftw3 again and document exactly what I do, but you might want to try troubleshooting yourself more.