我的目标是混合使用库FFTW的C代码。
#include
#include
#include"C:\\Users\\my_user_name\\Documents\\fftw-3.3.5-dll64\\fftw3.h"
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int i, j, bw, bw2_1, size, size2_1, nrow, ncol;
int data_is_real;
int cutoff;
int rank, howmany_rank;
double *rresult, *iresult, *rdata, *idata;
double *workspace, *weights;
fftw_plan dctPlan;
fftw_plan fftPlan;
fftw_iodim dims[1], howmany_dims[1];
bw = 2;
weights = (double *)malloc(sizeof(double) * 4 * bw);
rdata = (double *)malloc(sizeof(double) * 5 * bw);
dctPlan = fftw_plan_r2r_1d(2 * bw, weights, rdata, FFTW_REDFT10, FFTW_ESTIMATE);
}
我当前正在使用minGW,而不是Visual C ++。 如果(从Matlab)我打电话给
>>mex -c -LC:\\Users\\my_user_name\\Documents\\fftw-3.3.5-dll64 demo_fftw.c
它可以正确编译,但是正在运行
>> mex -LC:\\Users\\my_user_name\\Documents\\fftw-3.3.5-dll64 demo_fftw.c
Building with 'MinGW64 Compiler (C)'.
Error using mex C:\\Users\\MPUTHA~1\\AppData\\Local\\Temp\\mex_200676192178726_4216\\demo_fftw.obj:demo_fftw.c:(.text+0x40):undefined reference to `__imp_fftw_plan_r2r_1d'collect2.exe: error: ld returned 1 exit status
我认为该错误是因为尽管在fftw3.h中声明了fftw_plan_r2r_1d,但它是在链接器无法找到的其他地方定义的。 我知道,如果我使用的是Visual C ++,则.lib文件包含定义,但是自述文件仅告诉您如果使用的是Visual C ++,则编译该lib,而对于使用mingw则什么也没有说。
mingw的.lib文件相当于什么? 我还需要.lib吗? 如果是这样,我应该如何编译它们?
如果这个问题是重复的,我深表歉意,但是我环顾了一下,找到了很多建议,如果您使用的是Visual C ++,则可以使用,但与mingw无关。
看起来需要与fftw lib链接。 类似于-lfftw(使用-Lpathtolib提供库所在的路径
@ Jean-FranoisFabre所以我需要生成相应的库吗? 如何使用MinGW做到这一点?
在MinGW上,它将是DLL或.a文件。 lib文件是存根的,无论如何您都需要DLL。 您可以将fftw的二进制发行版用于Windows,而无需重新构建它。
您已经使编译器可以看到FFTW包含头文件。
现在,您需要链接到实际的FFTW代码。
幸运的是,FFTW的创建者对Windows用户很宽容,并在此处提供了预构建的发行版:http://www.fftw.org/install/windows.html
We have created precompiled DLL files for FFTW 3.3.5 in single/double/long-double precision, along with the associated test programs. We hope that these are sufficient for most users, so that you need not worry about compiling FFTW
These DLLs were created by us, cross-compiled from GNU/Linux using MinGW; the 64-bit version is possible thanks to the mingw-w64 project. You should be able to call them from any compiler.
所以MinGW很好。 在您的情况下,我会做(未测试):
mex -LC:\\Users\\my_user_name\\Documents\\fftw-3.3.5-dll64 demo_fftw.c libfftw3-3.dll
他们确实是仁慈的。 这可能与它们的库如此广泛使用的原因有关。 运行命令会显示错误错误,使用mex未知文件扩展名.dll。
是的,这个FFT库非常棒。 只要确保您的数据方向正确即可。 不要使用跨步!= 1,因为它会产生大量的高速缓存未命中。
我无法弄清楚为什么您的命令无法正常工作,但最终我发现安装了Visual C ++的计算机可以运行您的命令(将.dll替换为.lib)。 谢谢你的帮助