Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking FFTW into Matlab Mex file

I am trying to run FFTW code in a mex file. This is strictly for the purpose of development and testing. After some googling, I see that others have tried to do something similar and have had related problems, but I have not found any solutions. When attempting to run the mex file, Matlab tells me:

??? Error using ==> chirpTransform.mxCta Invalid MEX-file '\removed\my\directory\+chirpTransform\mxCta.mexw32': The specified procedure could not be found.

.

I am using gnumex with MinGW to build the mex file because LCC seems to have some issues. I have tried using the 32 bit DLL from the FFTW site (http://www.fftw.org/install/windows.html). I have tried using the fftwf3.dll in the Matlab 2009b bin directory. I built the dll from source using Msys/MinGW. In all cases, the results are the same. In all cases I did the following to generate the lib file.

c:\gnumex\mexdlltool.exe -d libfftw3f-3.def -D libfftw3f-3.dll -l libfftw3f.lib --as C:\MinGW\bin\as.exe

I also tried using the visual studio lib.exe tool and experimented with various mexdlltool flags.

It appears that I can directly call functions in the fftwf3-3.dll using Matlab's loadlibrary functionality. Since the DLL appears not to be the problem, I tried building a static version of fftwf3 and linking it directly into the mex file. I got the same results! If I remove the FFTW code, the mex file runs fine. I have just about given up at this point, and I am tyring to come up with alternative methods of testing.

like image 624
Todd Avatar asked Mar 24 '11 15:03

Todd


People also ask

How do I load a MEX file into MATLAB?

To call a MEX file, put the file on your MATLAB® path. Then type the name of the file, without the file extension. If you have MEX file source code, see Build C MEX Function for information about creating the executable function.

What is a MEX file in MATLAB?

A MEX file is a function, created in MATLAB, that calls a C/C++ program or a Fortran subroutine. A MEX function behaves just like a MATLAB script or function. To experiment with calling MEX functions, use the code in Tables of MEX Function Source Code Examples to build and run examples.

What is MEX compiler in MATLAB?

mex filenames compiles and links one or more C++ source files written with the MATLAB Data API for C++ into a binary MEX file in the current folder. For information about writing these applications, see Write C++ Functions Callable from MATLAB (MEX Files).


1 Answers

I've run into this issue with other mex functions. In my experience, it typically means that there is a dependency issue. Some dependency is not located.

Here is a link to TMW's documentation on this issue: Invalid MEX-File Error

Give it a read, and then try using dependency walker to diagnose the problem.

like image 161
hoogamaphone Avatar answered Sep 20 '22 04:09

hoogamaphone