我正在尝试在MATLAB MEX文件中使用FFTW库。我从FFTW.ORG获取此库用于Windows,并使用此代码生成lib文件
lib /def:libfftw3-3.def
lib /def:libfftw3f-3.def
lib /def:libfftw3l-3.def
然后当我使用此代码
直接在VC ++(Visual Studio 2013)中使用这些文件时#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "C:\Users\Maysam\Downloads\Compressed\fftw-3.3.4\api\fftw3.h"
#pragma comment(lib, "C:\\Windows\\SysWOW64\\libfftw3-3.lib")
void main()
{
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);
}
一切正常,编译时没有错误,但是当我尝试编译并使用此代码时
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "C:\Users\Maysam\Downloads\Compressed\fftw-3.3.4\api\fftw3.h"
#include <mex.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);
}
在MATLAB中使用mex
,如下所示
mex '-LC:\fftw-3.3.4-dll32' -llibfftw3-3.lib test.c
我收到此错误
Error using mex
Creating library test.lib and object test.exp
test.obj : error LNK2019: unresolved external symbol fftw_plan_r2r_1d referenced in function mexFunction
test.mexw64 : fatal error LNK1120: 1 unresolved externals
有人有建议或想法来解决这个问题吗?
答案 0 :(得分:1)
您需要将64位FFTW库与64位MATLAB相匹配(您正在构建.mexw64文件)。你的构建命令
mex '-LC:\fftw-3.3.4-dll32' -llibfftw3-3.lib test.c
应指向具有64位FFTW库的文件夹。例如:
mex -LC:\fftw-3.3.4-dll64 -llibfftw3-3.lib test.c