How to use FFTW lib file in MATLAB MEX file?

I am trying to use the FFTW library in MATLAB MATLAB. I get this library from FFTW.ORG for Windows and make lib files using this code

lib /def:libfftw3-3.def
lib /def:libfftw3f-3.def
lib /def:libfftw3l-3.def

      

Then when I use these 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 without 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 as shown below

mex '-LC:\fftw-3.3.4-dll32' -llibfftw3-3.lib test.c

      

I am getting 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

      

Does anyone have any advice or idea to fix this problem?

+3


source to share


1 answer


You need to map 64-bit FFTW library to 64-bit MATLAB (you create a .mexw64 file). Build command

mex '-LC:\fftw-3.3.4-dll32' -llibfftw3-3.lib test.c



Should point to the folder with 64-bit FFTW libraries. For example:

mex -LC:\fftw-3.3.4-dll64 -llibfftw3-3.lib test.c

+1


source







All Articles