0

Hello Fellow Matlab/OS X Users,

I was wondering if you can help me out once again. I got here a c-file (st.c, a Stockwell time-frequency analysis for MEG-Data) for Matlab which I should compile for my system (OS X Lion, Xcode 4.1.1). It includes

#include <fftw3.h>

So I downloaded the newest Version from http://www.fftw.org/ and compiled it. So far so good. But if I try to compile the c file

mex -st.c

I get the following error:

-> gcc-4.2 -O -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2011a.app/extern/lib/maci64/mexFunction.map -o  "st.mexmaci64"  st.o  -L/Applications/MATLAB_R2011a.app/bin/maci64 -lmx -lmex -lmat -lstdc++
Undefined symbols for architecture x86_64:
  "_fftw_destroy_plan", referenced from:
      _ist in st.o
      _st in st.o
  "_fftw_free", referenced from:
      _ist in st.o
      _st in st.o
  "_fftw_malloc", referenced from:
      _ist in st.o
      _st in st.o
  "_fftw_import_wisdom_from_file", referenced from:
      _ist in st.o
      _st in st.o
  "_fftw_plan_dft_1d", referenced from:
      _ist in st.o
      _st in st.o
  "_fftw_export_wisdom_to_file", referenced from:
      _ist in st.o
      _st in st.o
  "_fftw_execute", referenced from:
      _ist in st.o
      _st in st.o
  "_mexFunction", referenced from:
     -exported_symbol[s_list] command line option
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

    mex: link of ' "st.mexmaci64"' failed.

(I should say that compiling the c-file from the Matlab example (yprime.c) works without any problem.) By googling I couldnt find to much, but there was someone suggesting the following:

MATLAB needs to link 64-bit (x86_64). You'll need to find a working 64-bit gfortran compiler whose libraries are 64-bit and ABI-compatible with Apple's gcc.

Here http://r.research.att.com/tools/ I found GNU Fortran 4.2.4 for Mac OS X 10.7. But this didnt change anything, the error remains the same.

I guess the architecture is compiled in the wrong way, but I have no idea how to change that for Matlab/Xcode. If this is the case, could someone pls tell me how to do it ?

Thanks for your Help

Irreducible
  • 864
  • 11
  • 24
  • 2
    It looks like you haven’t compiled FFTW for x86_64 or it is not being linked against your program. Can you check that? –  Sep 06 '11 at 15:07
  • I droped the fft3w.h & fft3w.f into the matlabroot/extern/include If i take it out of there I get the following error-msg: `fftw3.h: No such file or directory`. I am not very familiar with mex and gcc, which is the best way to check if it is compiled and linked in the right way ? – Irreducible Sep 06 '11 at 18:16
  • And I’m not familiar with neither FFTW nor Fortran nor MATLAB, heh. That said, it looks like when `mex` invokes `gcc` it’s not passing the FFTW library — at least I can’t identify it on that `gcc` line. Or maybe it is, but FFTW hasn’t bee compiled for x86_64. If you have a FFTW library (maybe with .o, .a, or .dylib extensions), run `lipo -info` against it and it’ll tell you the architectures for which it’s been compiled. –  Sep 06 '11 at 18:29
  • I found the libfftw3.a and it seems like the architecture is correct or ? `Non-fat file: libfftw3.a is architecture: x86_64` – Irreducible Sep 06 '11 at 19:05
  • Great. So, as far as I can tell, you need to figure out how to tell `mex` that it should link that libfftw3.a file since it doesn’t show up in that `gcc` line. It should appear either as is or as `-lfftw3`. –  Sep 06 '11 at 19:07
  • @Irreducible: I think you need to specify where the compiler/linker should look for the header files and libraries: `mex prog.c -I/path/include -L/path/lib/ -lfftw`. You can check the [documentation](http://www.mathworks.com/help/techdoc/matlab_external/f24338.html#f24347) [pages](http://www.mathworks.com/help/techdoc/ref/mex.html) for complete details. – Amro Sep 07 '11 at 02:51

1 Answers1

0

You need to link against the fftw library. You can pass linker flags directly to the mex command. So you probably want to issue a command like:

>> mex -v -I/path/to/fftw/include -L/path/to/fftw/lib/ -lfftw3 st.c

The -v option will put mex into verbose mode and will print out the gcc commands used to compile and link the mex file. This output is helpful for debugging linking problems

codehippo
  • 1,379
  • 1
  • 8
  • 19
  • Now I get that error: `gcc-4.2 -O -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2011a.app/extern/lib/maci64/mexFunction.map -o "st.mexmaci64" st.o -L/usr/local/lib/ -lfftw3 -L/Applications/MATLAB_R2011a.app/bin/maci64 -lmx -lmex -lmat -lstdc++ Undefined symbols for architecture x86_64: "_mexFunction", referenced from: -exported_symbol[s_list] command line option ld: symbol(s) not found for architecture x86_64` – Irreducible Sep 08 '11 at 10:14
  • 1
    I found here [link](http://stackoverflow.com/questions/2188658/shared-library-locations-for-matlab-mex-files) an answer which let me compile my c file: `mex CFLAGS='-I/usr/local/lib' LDFLAGS='-t /usr/local/lib/libfftw3.a -lz -bundle' st.c -v` – Irreducible Sep 08 '11 at 10:18