Can I build a C++ MEX file using Xcode 5 on Mac OS X 10.9?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
David
el 1 de Abr. de 2014
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.
Respuestas (1)
Bernard
el 29 de Abr. de 2014
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.
1 comentario
Ver también
Categorías
Más información sobre Call C++ from MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!