Cannot debug C++ MEX-file with Xcode on Mac Platform
2 views (last 30 days)
Show older comments
First, I followed the debug instruction on http://au.mathworks.com/help/matlab/matlab_external/debugging-on-mac-platforms.html, and run debugging "yprime.c" successfully.
But this method does not work when I try to debug C++ MEX-file. Xcode debugger cannot stop at breakpoints where I set. I double checked all settings are correct.
Then I try to figure out the problem.
1. I run the command and found out no object files that Xcode use for debugging were generated:
mex -g BallTreeDensity.cpp BallTreeClass.cc BallTreeDensityClass.cc
After I run the command as follow, I found at the end of output, the mex script delete those object files:
mex -g -v BallTreeDensity.cpp BallTreeClass.cc BallTreeDensityClass.cc
Here is the output:
Verbose mode is on.
Neither -compatibleArrayDims nor -largeArrayDims is selected.
Using -compatibleArrayDims. In the future, MATLAB will require the use of
-largeArrayDims and remove the -compatibleArrayDims option.
For more information:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
No MEX options file identified; looking for an implicit selection.
... Looking for compiler 'Xcode Clang++' ...
... Looking for environment variable 'DEVELOPER_DIR' ...No.
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer' ...Yes.
... Executing command 'which xcrun' ...Yes ('/Applications/Xcode.app/Contents/Developer/usr/bin/xcrun').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/usr/bin' ...Yes.
... Executing command 'defaults read com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...No.
... Executing command 'defaults read /Library/Preferences/com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense' ...Yes ('6.1.1').
... Executing command '
agreed=6.1.1
if echo $agreed | grep -E '[\.\"]' >/dev/null; then
lhs=`expr "$agreed" : '\([0-9]*\)[\.].*'`
rhs=`expr "$agreed" : '[0-9]*[\.]\(.*\)$'`
if echo $rhs | grep -E '[\."]' >/dev/null; then
rhs=`expr "$rhs" : '\([0-9]*\)[\.].*'`
fi
if [ $lhs -gt 4 ] || ( [ $lhs -eq 4 ] && [ $rhs -ge 3 ] ); then
echo $agreed
else
exit 1
fi
fi' ...Yes ('6.1.1').
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk' ...Yes.
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/Xcode.app/Contents/Developer').
... Looking for folder '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk' ...Yes.
... Executing command 'echo /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk | rev | cut -c1-10 | rev | egrep -oh '[0-9]+\.[0-9]+'' ...Yes ('10.9').
Found installed compiler 'Xcode Clang++'.
Options file details
-------------------------------------------------------------------
Compiler location: /Applications/Xcode.app/Contents/Developer
Options file: /Applications/MATLAB_R2015a.app/bin/maci64/mexopts/clang++_maci64.xml
CMDLINE200 : /Applications/Xcode.app/Contents/Developer/usr/bin/xcrun -sdk macosx10.9 clang++ -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.9 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -framework Cocoa -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2015a.app/extern/lib/maci64/mexFunction.map" -stdlib=libc++ -g -Wl,-exported_symbols_list,"/Applications/MATLAB_R2015a.app/extern/lib/maci64/mexFunction.map" BallTreeDensity.o BallTreeClass.o BallTreeDensityClass.o -L"/Applications/MATLAB_R2015a.app/bin/maci64" -lmx -lmex -lmat -o BallTreeDensity.mexmaci64
CXX : /Applications/Xcode.app/Contents/Developer/usr/bin/xcrun -sdk macosx10.9 clang++
DEFINES : -DMX_COMPAT_32 -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CXXFLAGS : -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -fobjc-arc -std=c++11 -stdlib=libc++
INCLUDE : -I"/Applications/MATLAB_R2015a.app/extern/include" -I"/Applications/MATLAB_R2015a.app/simulink/include"
CXXOPTIMFLAGS : -O2 -DNDEBUG
CXXDEBUGFLAGS : -g
LDXX : /Applications/Xcode.app/Contents/Developer/usr/bin/xcrun -sdk macosx10.9 clang++
LDFLAGS : -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.9 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -framework Cocoa -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2015a.app/extern/lib/maci64/mexFunction.map" -stdlib=libc++
LDBUNDLE : -bundle
LINKEXPORT : -Wl,-exported_symbols_list,"/Applications/MATLAB_R2015a.app/extern/lib/maci64/mexFunction.map"
LINKLIBS : -L"/Applications/MATLAB_R2015a.app/bin/maci64" -lmx -lmex -lmat
LDOPTIMFLAGS : -O
LDDEBUGFLAGS : -g
OBJEXT : .o
LDEXT : .mexmaci64
DEVELOPER_DIR_CHECK :
XCODE_DIR : /Applications/Xcode.app/Contents/Developer
XCRUN_DIR : /Applications/Xcode.app/Contents/Developer/usr/bin
XCODE_AGREED_VERSION : 6.1.1
ISYSROOT : /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
SDKVER : 10.9
MATLABROOT : /Applications/MATLAB_R2015a.app
ARCH : maci64
SRC : /Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeDensity.cpp;/Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeClass.cc;/Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeDensityClass.cc
OBJ : BallTreeDensity.o;BallTreeClass.o;BallTreeDensityClass.o
OBJS : BallTreeDensity.o BallTreeClass.o BallTreeDensityClass.o
SRCROOT : /Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeDensity
DEF : /var/folders/mw/k9r9hgf50tq3xv_5vgck1v2m0000gn/T//mex_1863173812270_1489/BallTreeDensity.def
EXP : BallTreeDensity.exp
LIB : BallTreeDensity.lib
EXE : BallTreeDensity.mexmaci64
ILK : BallTreeDensity.ilk
MANIFEST : BallTreeDensity.mexmaci64.manifest
TEMPNAME : BallTreeDensity
EXEDIR :
EXENAME : BallTreeDensity
OPTIM : -g
LINKOPTIM : -g
CMDLINE100_0 : /Applications/Xcode.app/Contents/Developer/usr/bin/xcrun -sdk macosx10.9 clang++ -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2015a.app/extern/include" -I"/Applications/MATLAB_R2015a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -fobjc-arc -std=c++11 -stdlib=libc++ -g /Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeDensity.cpp -o BallTreeDensity.o
CMDLINE100_1 : /Applications/Xcode.app/Contents/Developer/usr/bin/xcrun -sdk macosx10.9 clang++ -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2015a.app/extern/include" -I"/Applications/MATLAB_R2015a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -fobjc-arc -std=c++11 -stdlib=libc++ -g /Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeClass.cc -o BallTreeClass.o
CMDLINE100_2 : /Applications/Xcode.app/Contents/Developer/usr/bin/xcrun -sdk macosx10.9 clang++ -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2015a.app/extern/include" -I"/Applications/MATLAB_R2015a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -fobjc-arc -std=c++11 -stdlib=libc++ -g /Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeDensityClass.cc -o BallTreeDensityClass.o
CMDLINE300_0 : rm -f BallTreeDensity.o
CMDLINE300_1 : rm -f BallTreeClass.o
CMDLINE300_2 : rm -f BallTreeDensityClass.o
-------------------------------------------------------------------
Building with 'Xcode Clang++'.
/Applications/Xcode.app/Contents/Developer/usr/bin/xcrun -sdk macosx10.9 clang++ -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2015a.app/extern/include" -I"/Applications/MATLAB_R2015a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -fobjc-arc -std=c++11 -stdlib=libc++ -g /Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeDensity.cpp -o BallTreeDensity.o
In file included from /Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeDensity.cpp:9:
In file included from /Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeDensity.h:16:
/Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTree.h:64:63: warning: comparison of 0 <= unsigned expression is always true [-Wtautological-compare]
bool validIndex(BallTree::index ind) const { return ((0<=ind) && (ind < 2*num_points)); }
~^ ~~~
1 warning generated.
/Applications/Xcode.app/Contents/Developer/usr/bin/xcrun -sdk macosx10.9 clang++ -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2015a.app/extern/include" -I"/Applications/MATLAB_R2015a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -fobjc-arc -std=c++11 -stdlib=libc++ -g /Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeClass.cc -o BallTreeClass.o
In file included from /Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeClass.cc:16:
/Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTree.h:64:63: warning: comparison of 0 <= unsigned expression is always true [-Wtautological-compare]
bool validIndex(BallTree::index ind) const { return ((0<=ind) && (ind < 2*num_points)); }
~^ ~~~
1 warning generated.
/Applications/Xcode.app/Contents/Developer/usr/bin/xcrun -sdk macosx10.9 clang++ -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"/Applications/MATLAB_R2015a.app/extern/include" -I"/Applications/MATLAB_R2015a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -fobjc-arc -std=c++11 -stdlib=libc++ -g /Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeDensityClass.cc -o BallTreeDensityClass.o
In file included from /Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeDensityClass.cc:14:
In file included from /Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTreeDensity.h:16:
/Users/ideepblue/Documents/MATLAB/third-party/@kde/t/BallTree.h:64:63: warning: comparison of 0 <= unsigned expression is always true [-Wtautological-compare]
bool validIndex(BallTree::index ind) const { return ((0<=ind) && (ind < 2*num_points)); }
~^ ~~~
1 warning generated.
/Applications/Xcode.app/Contents/Developer/usr/bin/xcrun -sdk macosx10.9 clang++ -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.9 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -framework Cocoa -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2015a.app/extern/lib/maci64/mexFunction.map" -stdlib=libc++ -g -Wl,-exported_symbols_list,"/Applications/MATLAB_R2015a.app/extern/lib/maci64/mexFunction.map" BallTreeDensity.o BallTreeClass.o BallTreeDensityClass.o -L"/Applications/MATLAB_R2015a.app/bin/maci64" -lmx -lmex -lmat -o BallTreeDensity.mexmaci64
rm -f BallTreeDensity.o
rm -f BallTreeClass.o
rm -f BallTreeDensityClass.o
MEX completed successfully.
2. Then I use the command as follow to generate object file only:
mex -c -g -v BallTreeDensity.cpp BallTreeClass.cc BallTreeDensityClass.cc
But Xcode debugging still does not work.
I try my best to solve this problem, but still got nothing.
So, my question is how to debug c++ mex file on Mac platform?
0 Comments
Accepted Answer
Varun Bhaskar
on 12 Aug 2015
Hello,
1) What is the output generated for mex -g -v yprime.cpp? 2) Can you place mexopts.sh in your preferences directory or current working directory and then try debugging? 3) Can you Use the mex build script option -largeArrayDims with the 64-bit API?
More Answers (0)
See Also
Categories
Find more on C Shared Library Integration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!