0

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
drakon101
  • 524
  • 1
  • 8
  • 1
    `-L` is for the directory where the linker will look for library files. You also need to do `-l` (lowercase L) to specify which library to link to. – Cris Luengo Mar 02 '22 at 20:40
  • That makes sense and seems consistent with the documentation. However, I'm still getting an error where it can't seem to even find the library now. – drakon101 Mar 07 '22 at 16:54
  • It would typically be `-lmwfftw3` on Linux, not sure how that works on Windows. Do you have a `libmwfftw3.lib` file on your machine? If you only have a DLL file, you might have to provide the full file name, including extension? Again, not sure how this works on Windows. – Cris Luengo Mar 07 '22 at 17:50
  • I can't actually find a .lib file, just the .dll file. I've tried '-llibmwfftw3.dll' but the error message just looks like the error message from Update 1 but with 'libmwfftw3.dll.lib'. In other words, the mex command doesn't seem to recognize the .dll extension. – drakon101 Mar 07 '22 at 18:42
  • I also tried '-lmwfftw3' and the error message says it couldnt find mwfftw3.lib or libmwfftw3.lib. Clearly it should work, but for some reason the mex command isn't recognizing that it should check a shared library. Googling or searching how to use shared libraries with mex doesn't seem to help either.. – drakon101 Mar 07 '22 at 18:44
  • 1
    You could create an import library (.lib) from your DLL. See here: https://stackoverflow.com/q/9946322/7328782 – Cris Luengo Mar 07 '22 at 19:56

0 Answers0