MATLAB: Xcode 5 : link fails – clang

clanglink fails

I've tried to install the nfft package on my MacBook Pro OS X 10.9, using Xcode 5. The config.log relative to the nfft installation is attached. When I test the nfft package, I have to compile a .c file using the following command:
if true
fftw3Path='/Users/boyer/Documents/MATLAB/fftw-3.3.4/';
nfft3Path='/Users/boyer/Documents/MATLAB/nfft-3.2.3/';
Ipath=[' -I' nfft3Path 'include ' ' -I' nfft3Path 'applications/fastsum ' '-I' fftw3Path 'api ' '-I' nfft3Path 'matlab ' ];
Lpath=['-L' nfft3Path ' ' '-L' nfft3Path 'applications/fastsum' ' ' '-L' fftw3Path 'api' ];
command=sprintf(['mex -v -Dchar16_t=uint16_t ' Lpath ' ' Ipath ' -lfftw3 -lnfft3 nfftmex.c']);
eval(command)
end
Here is the answer that I get:
if true
Building with 'Xcode with Clang'.
/usr/bin/xcrun -sdk macosx10.8 clang -c -Dchar16_t=uint16_t -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I/Users/boyer/Documents/MATLAB/nfft-3.2.3/include -I/Users/boyer/Documents/MATLAB/nfft-3.2.3/applications/fastsum -I/Users/boyer/Documents/MATLAB/fftw-3.3.4/api -I/Users/boyer/Documents/MATLAB/nfft-3.2.3/matlab -I"/Applications/MATLAB_R2014a.app/extern/include" -I"/Applications/MATLAB_R2014a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.8 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -O2 -DNDEBUG /Users/boyer/Documents/MATLAB/nfft-3.2.3/matlab/nfft/nfftmex.c -o /var/folders/_0/63lwd1z17j94w_7wgkrw3x700000gn/T//mex_2747778005296_34460/nfftmex.o
/usr/bin/xcrun -sdk macosx10.8 clang -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.8 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map" /var/folders/_0/63lwd1z17j94w_7wgkrw3x700000gn/T//mex_2747778005296_34460/nfftmex.o -O -Wl,-exported_symbols_list,"/Applications/MATLAB_R2014a.app/extern/lib/maci64/mexFunction.map" -lfftw3 -lnfft3 -L/Users/boyer/Documents/MATLAB/nfft-3.2.3/ -L/Users/boyer/Documents/MATLAB/nfft-3.2.3/applications/fastsum -L/Users/boyer/Documents/MATLAB/fftw-3.3.4/api -L"/Applications/MATLAB_R2014a.app/bin/maci64" -lmx -lmex -lmat -lstdc++ -o nfftmex.mexmaci64
Error using mex
Undefined symbols for architecture x86_64:
"_nfft_mex_get_int", referenced from:
_mexFunction in nfftmex.o
"_nfft_mex_install_mem_hooks", referenced from:
_mexFunction in nfftmex.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
end
Using MatlabR2011b, I have changed the mexopts.sh file replacing the version by 10.9: CC='llvm-gcc' CXX='llvm-g++' SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/'
I have also tried to change the libraries -lstdc++ by -std=libstdc++. Nothing solves the problem.
Then I used MatlabR2014a, and I have the same error (but in this version, we cannot modify the mexopts.sh, it seems to have been replaced by mex_C_maci64.xml).
I think that maybe I will install another c-compiler which is too bad since at least MatlabR2014a is supposed to be compatible with Xcode5.
If you have any suggestion, thank you in advance.

Best Answer

It seems to work by applying the following command when installing the nfft package (before make and make install):
./configure --with-fftw3='/usr/local' --with-fftw3-libdir='/usr/local/lib' --with-fftw3-includedir='/usr/local/include' --with-matlab='/Applications/MATLAB_R2014a.app' --with-matlab-fftw3-libdir='/usr/local/lib'
Another comment: even if the version of OS X is 10.9, matlab selects 10.8sdk. To avoid this, you can edit the file mex_C_maci64.xml, and invert 2 lines of codes:
if true
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk" />
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk" />
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk" />
<cmdReturns name="find $$ -name MacOSX10.7.sdk" />
<cmdReturns name="find $$ -name MacOSX10.9.sdk" />
<cmdReturns name="find $$ -name MacOSX10.8.sdk" />
end
instead of
if true
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk" />
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk" />
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk" />
<cmdReturns name="find $$ -name MacOSX10.7.sdk" />
<cmdReturns name="find $$ -name MacOSX10.8.sdk" />
<cmdReturns name="find $$ -name MacOSX10.9.sdk" />
end
Hope it can help.
Related Question