This is my mex command:
currentDir = cd;currentDir = regexp(currentDir, filesep, 'split');
ipath = ['-I' fullfile(currentDir{1:end-1},'eigen-3.4.0')];
mex(ipath,lpathFFTW,...
'CXXFLAGS="$CXXFLAGS -march=native -std=c++14 -fno-math-errno -ffast-math -fopenmp -DNDEBUG"',...
'LDFLAGS="$LDFLAGS -fopenmp"',...
'CXXOPTIMFLAGS="-O3"',...
'computeDASBMode.cpp','computeDAShelper.cpp',...
'-outdir',outputFolder)
I've tried the following things as an option for lpathFFTW with the corresponding errors each trial gives:
Trial 1: where libfftw3-3.dll is in the target path
lpathFFTW = ['-L' fullfile(currentDir{1:end-1},'fftw-3.3.5-dll64','libfftw3-3.lib')];
error:
Error using mex
C:\Users\nikun\AppData\Local\Temp\mex_516976837146_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x128b): undefined reference to `__imp_fftw_import_wisdom_from_filename'
C:\Users\nikun\AppData\Local\Temp\mex_516976837146_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x12f0): undefined reference to `__imp_fftw_plan_many_dft'
C:\Users\nikun\AppData\Local\Temp\mex_516976837146_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x135d): undefined reference to `__imp_fftw_export_wisdom_to_filename'
collect2.exe: error: ld returned 1 exit status
Trial 2: using the fftw library from matlab's root folder
lpathFFTW = ['-L',fullfile(matlabroot,'bin',computer('arch'),'libmwfftw3.lib')];
error:
Error using mex
C:\Users\nikun\AppData\Local\Temp\mex_1088299880810_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x128b): undefined reference to `__imp_fftw_import_wisdom_from_filename'
C:\Users\nikun\AppData\Local\Temp\mex_1088299880810_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x12f0): undefined reference to `__imp_fftw_plan_many_dft'
C:\Users\nikun\AppData\Local\Temp\mex_1088299880810_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x135d): undefined reference to `__imp_fftw_export_wisdom_to_filename'
collect2.exe: error: ld returned 1 exit status
TLDR: I tried to compile a mex function linking the FFTW libraries using either the dll from fftw's website or the dll from matlab. Both seem to fail.
Update I tried this in response to @Cris Luengo's comment:
lpathFFTW = ['-L',fullfile(matlabroot,'bin',computer('arch'))];
mex(ipath,lpathFFTW,'-llibmwfftw3.lib',...
'CXXFLAGS="$CXXFLAGS -march=native -std=c++14 -fno-math-errno -ffast-math -fopenmp -DNDEBUG"',...
'LDFLAGS="$LDFLAGS -fopenmp"',...
'CXXOPTIMFLAGS="-O3"',...
'computeDASBMode.cpp','computeDAShelper.cpp',...
'-outdir',outputFolder)
yielding the following error:
Error using mex
MEX cannot find library 'libmwfftw3', specified with the -l option.
MEX searched for a file with one of the following names:
libmwfftw3.lib
liblibmwfftw3.lib
Verify the library name is correct. If the library is not
on the existing path, specify the path with the -L option.
Update 2 I also tried this but got the following error:
lpathFFTW = ['-L',fullfile(matlabroot,'bin',computer('arch'))];
mex(ipath,lpathFFTW,...
'CXXFLAGS="$CXXFLAGS -march=native -std=c++14 -fno-math-errno -ffast-math -fopenmp -DNDEBUG"',...
'LDFLAGS="$LDFLAGS -fopenmp"',...
'LINKLIBS="$LINKLIBS -llibmwfftw3"',...
'CXXOPTIMFLAGS="-O3"',...
'computeDASBMode.cpp','computeDAShelper.cpp',...
'-outdir',outputFolder,'-v')
C:/ProgramData/MATLAB/SupportPackages/R2020b/3P.instrset/mingw_w64.instrset/bin/../lib/gcc/x86_64-w64-mingw32/6.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -llibmwfftw3
collect2.exe: error: ld returned 1 exit status