From: kk KKsingh on
"Chris Turnes" <cturnes(a)gmail.com> wrote in message <i24v95$4lt$1(a)fred.mathworks.com>...
>
> > ??? 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.


Hey Chris !

I am getting error

>> mex -g -v potts_ndft.c /usr/local/lib/libnfft3.a /usr/local/lib/libfftw3.a -lm
-> mexopts.sh sourced from directory (DIR = $HOME/.matlab/$REL_VERSION)
FILE = /disk/jelly1/agulati/.matlab/R2009b/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /disk/gilgamesh1/software/llmatlab-2009b
-> CC = gcc
-> CC flags:
CFLAGS = -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread
CDEBUGFLAGS = -g
COPTIMFLAGS = -O -DNDEBUG
CLIBS = -Wl,-rpath-link,/disk/gilgamesh1/software/llmatlab-2009b/bin/glnxa64 -L/disk/gilgamesh1/software/llmatlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
arguments = -DMX_COMPAT_32
-> CXX = g++
-> CXX flags:
CXXFLAGS = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O -DNDEBUG
CXXLIBS = -Wl,-rpath-link,/disk/gilgamesh1/software/llmatlab-2009b/bin/glnxa64 -L/disk/gilgamesh1/software/llmatlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> FC = g95
-> FC flags:
FFLAGS = -fexceptions -fPIC -fno-omit-frame-pointer
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -Wl,-rpath-link,/disk/gilgamesh1/software/llmatlab-2009b/bin/glnxa64 -L/disk/gilgamesh1/software/llmatlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> LD = gcc
-> Link flags:
LDFLAGS = -pthread -shared -Wl,--version-script,/disk/gilgamesh1/software/llmatlab-2009b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexa64
arguments = /usr/local/lib/libnfft3.a /usr/local/lib/libfftw3.a -lm
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments = /usr/local/lib/libnfft3.a /usr/local/lib/libfftw3.a -lm
----------------------------------------------------------------

-> gcc -c -I/disk/gilgamesh1/software/llmatlab-2009b/extern/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -g "potts_ndft.c"

-> gcc -g -pthread -shared -Wl,--version-script,/disk/gilgamesh1/software/llmatlab-2009b/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -o "potts_ndft.mexa64" potts_ndft.o /usr/local/lib/libnfft3.a /usr/local/lib/libfftw3.a -lm -Wl,-rpath-link,/disk/gilgamesh1/software/llmatlab-2009b/bin/glnxa64 -L/disk/gilgamesh1/software/llmatlab-2009b/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++


/usr/bin/ld: /usr/local/lib/libfftw3.a(plan-dft.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libfftw3.a: could not read symbols: Bad value
collect2: ld returned 1 exit status

mex: link of ' "potts_ndft.mexa64"' failed
??? Error using ==> mex at 221
Unable to complete successfully.

What you think about this ! Even when i run this libray with c is use -static with gcc to avoid shared libraries..... do have any option like that in matlab
From: Chris Turnes on
This might answer your question:

http://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3

Try recompiling your libraries with the -fPIC flag.
From: kk KKsingh on
"Chris Turnes" <cturnes(a)gmail.com> wrote in message <i25400$ak8$1(a)fred.mathworks.com>...
> This might answer your question:
>
> http://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3
>
> Try recompiling your libraries with the -fPIC flag.

I am not sure what -fpic is doing ! But what i understand it is added to CFLAGS (and unused CXXFLAGS) - need to generate position independent code for shared library

So
MEX [option1 ... optionN] sourcefile1 [... sourcefileN]
[objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN]


it will be some thing like
mex -v -g CFLAGS = '-fpic -I/usr/local/include' LDFLAGS=' -t/usr/local/lib -shared' potts_nfft.c /usr/local/lib/libnfft3.a /usr/local/include/libfftw3.a

which is wrong sorry ! I am not aware of fpic
From: kk KKsingh on
"Chris Turnes" <cturnes(a)gmail.com> wrote in message <i25400$ak8$1(a)fred.mathworks.com>...
> This might answer your question:
>
> http://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3
>
> Try recompiling your libraries with the -fPIC flag.

HI Chris here is the simple solution !

Please add the path of .so file in LD_LIBRARY_PATH and it wont be a problem to write such a long thing !

finally now i know why it was not linking ! some time we make small mistakes

Thanks
Akshay