I am trying to use the FFTW library in a MATLAB MEX-file. I get this library from FFTW.ORG for Windows and make lib files by using this code
lib /def:libfftw3-3.def
lib /def:libfftw3f-3.def
lib /def:libfftw3l-3.def
Then when I use those files directly in VC++ (Visual Studio 2013) with this code
#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);
}
everything is OK and compiles with no error, but when I try to compile and use this code
#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);
}
with mex in MATLAB like below
mex '-LC:\fftw-3.3.4-dll32' -llibfftw3-3.lib test.c
I get this error
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
Do anyone has advice or an idea to solve this problem?
You need to match a 64-bit FFTW library with 64-bit MATLAB (you are building a .mexw64 file). Your build command
mex '-LC:\fftw-3.3.4-dll32' -llibfftw3-3.lib test.c
Should point to a folder with the 64-bit FFTW libraries. For example:
mex -LC:\fftw-3.3.4-dll64 -llibfftw3-3.lib test.c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With