Can I build a C++ MEX file using Xcode 5 on Mac OS X 10.9?
3 ビュー (過去 30 日間)
古いコメントを表示
I would like to be able to build MEX files using the Xcode 5 IDE on OS X 10.9 (Mavericks) with Matlab 2013b.
I saw this related question involving what was presumably Xcode 4 on an earlier version of OS X and Matlab, but some of the steps seem different or not applicable.
I initially attempted to build the built-in mexcpp.cpp file using Xcode (on my computer, mexcpp.cpp is /Applications/MATLAB_R2013b.app/extern/examples/mex/mexcpp.cpp). Here's what I did:
- Create a new Xcode project (OS X -> Application -> Command Line Tool)
- Call it "mex xcode test", type C++
- Rename main.cpp to mexcpp.cpp
- Copy contents of matlab's mexcpp.cpp to my mexcpp.cpp
- Under Target -> Build Settings, add the following User Header Search Paths:
- /Applications/MATLAB_R2013b.app/extern/include (non-recursive)
- Under Target -> Build Settings, add the following Library Search Paths:
- /Applications/MATLAB_R2013b.app/sys/os/maci64 (non-recursive)
- /Applications/MATLAB_R2013b.app/bin/maci64 (recursive)
- Under Target -> Build Settings, set "Always Search User Paths" to Yes
- Build via Product -> Build
Ignoring the "missing main.cpp" warning, I get the following linker errors:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
"_mexErrMsgIdAndTxt", referenced from:
_mexFunction in mexcpp.o
"_mxGetPr", referenced from:
_mexFunction in mexcpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I added some more steps from the instructions at http://www.mathworks.com/help/matlab/matlab_external/custom-building-mex-files.html#f24496
- Under Target -> Build Settings, add preprocessor macro MATLAB_MEX_FILE to both Debug and Release phases
This made no difference.
- Under Target -> Build Phases -> Link Binary with Libraries, I added several explicit libraries (but shouldn't these be found automatically based on my library search path?):
- /Applications/MATLAB_R2013b.app/bin/maci64/libeng.dylib
- /Applications/MATLAB_R2013b.app/bin/maci64/libmx.dylib
This solved my linker problem to mxGetPr, so my linker error message is now shorter:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
"_mexErrMsgIdAndTxt", referenced from:
_mexFunction in mexcpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Is the solution then to somehow figure out which explicit library files I need for every C++ function that I write? This seems unsustainable, since there are over 500 library files in the /Applications/MATLAB_R2013b.app/bin/maci64 folder. Or am I missing a step in telling Xcode where to find the library files?
And will adding the right library files solve my error involving the _main symbol? Or do I need to somehow tell Xcode to build a library instead of an executable?
What steps am I missing?
Thank you!
1 件のコメント
David
2014 年 4 月 1 日
Hi, did you ever solve this problem? I am having the same issues right now. Also, in Xcode 5.1 you can't type in the explicit path to libraries like you did above.
回答 (1 件)
Bernard
2014 年 4 月 29 日
Hi
I could make it work by setting Mach-O Type to Bundle (in Linking). Also, I used "-lmx -lmex -lmat" in Other Linker Flags to specify the libraries.
参考
カテゴリ
Help Center および File Exchange で Install Products についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!