From: John on
I hope you have figured out the problem. Did you dynamically link to fftw3.so? I ran into the same problem, and after searching it turns out that matlab has their own fftw3.so library that it loads before any thing in your LD_LIBRARY_PATH. I tried to link to this version (supplied by matlab) but it still crashed.
So the solution is ugly: link statically to libfftw3.a. That fixes it. If you know a solution that still use dynamic link, please let me know.


"Chris Turnes" <cturnes(a)gmail.com> wrote in message <hu8qe0$iqk$1(a)fred.mathworks.com>...
> I'm trying to write a c++ mex program that references the FFTW3 and NFFT3 libraries. When I mex compile, there are no errors and everything works fine. When I attempt to run the code, I get this exception, which terminates MATLAB:
>
> ------------------------------------------------------------------------
> Segmentation violation detected at Thu Jun 3 13:57:09 2010
>
From: kk KKsingh on
"John " <thnguyen16(a)uh.edu> wrote in message <i1sjqj$oph$1(a)fred.mathworks.com>...
> I hope you have figured out the problem. Did you dynamically link to fftw3.so? I ran into the same problem, and after searching it turns out that matlab has their own fftw3.so library that it loads before any thing in your LD_LIBRARY_PATH. I tried to link to this version (supplied by matlab) but it still crashed.
> So the solution is ugly: link statically to libfftw3.a. That fixes it. If you know a solution that still use dynamic link, please let me know.
>
>
> "Chris Turnes" <cturnes(a)gmail.com> wrote in message <hu8qe0$iqk$1(a)fred.mathworks.com>...
> > I'm trying to write a c++ mex program that references the FFTW3 and NFFT3 libraries. When I mex compile, there are no errors and everything works fine. When I attempt to run the code, I get this exception, which terminates MATLAB:
> >
> > ------------------------------------------------------------------------
> > Segmentation violation detected at Thu Jun 3 13:57:09 2010
> >

try this

mex -v file.c -lnfft3 -lfftw3

it will work ! But i think i need to add path of dynamic libray (.so) in my path ! Did u tried nfft c code chris till now
From: Chris Turnes on
Thanks to both of you; I figured this out a few weeks ago but forgot to follow up.

Yes, you must statically link the library because of the conflict with MATLAB's separate FFTW. For some reason no matter how hard I tried to add the location of the static libraries to the linking directories, in the end I just specified the entire path of each library, and that did that trick.
From: kk KKsingh on
"Chris Turnes" <cturnes(a)gmail.com> wrote in message <i243ud$ash$1(a)fred.mathworks.com>...
> Thanks to both of you; I figured this out a few weeks ago but forgot to follow up.
>
> Yes, you must statically link the library because of the conflict with MATLAB's separate FFTW. For some reason no matter how hard I tried to add the location of the static libraries to the linking directories, in the end I just specified the entire path of each library, and that did that trick.

So can you tell me solution of this error, which occurs when i try to use mex file in the function..;

??? Invalid MEX-file
'/disk/diansour/agulati/Matlabdir/irt/nufft/akiexamples/potts_nfft.mexa64':
libnfft3.so.0: cannot open shared object file: No such file or directory.

This file
libnfft3.so@

is in the some path /usr/local/lib

so how will i link it to Matlab now....

Thanks for the help
From: Chris Turnes on

> ??? Invalid MEX-file
> '/disk/diansour/agulati/Matlabdir/irt/nufft/akiexamples/potts_nfft.mexa64':
> libnfft3.so.0: cannot open shared object file: No such file or directory.
>
> This file
> libnfft3.so@
>

When I linked it, I had to do something like this:

mex -g my_file.cpp /usr/local/lib/libnfft3.a /usr/local/lib/libfftw3.a -lm;

It isn't pretty, but it works. Also, make sure you link the math, the FFTW, and the NFFT3 libraries in the right order. You'll run into undefined symbol errors if you don't.