Connect with users of Wolfram technologies to learn, solve problems and share ideas
Mark as an Answer
3 Total Likes
Follow this post
Share this post:
The Missing Documentation of Building MathLink project with XCode(4.6.2)
Shenghui Yang, WOLFRAM
11 years ago
Because the XCode's interface has been modified drastically since version 3, I could not use the current documentation in version 9 to construct my project. I am writing down this documentation for your reference. Feel free to let me know if you find any error or think improvements can be added.
Goal: Create a C/C++ project that use the Mathematica Kernel
Platform: Mac OSX 10.8+
IDE: XCode 4.6.3
Mathematica 8+ is installed on your machine and activated. Normally under /Applications.
Create a symbolic link to Mathematica Kernel, e.g.
sudo ln -s /Applications/Mathematica.app/Contents/MacOS/MathKernel /usr/local/bin/math
You have XCode 4.6.3 installed and Command Line Tools is istalled (gcc is required)
Now buckle up and we are going to start build our very first project in the latest XCode
Launch XCode and choose "create a new XCode project" from the welcoming window. Or you can do this from Menu bar: File -> New -> Project
Then choose OSX/Application -> Command Line Tool. Hit "Next"
You just type your project name such as "mathlink" and other info in the input bars and Choose "Type" -> C for our project. The check box underneath does not matter. Leave it checked would be OK. Hit "Next" button.
hoose a directory to save your project. Just for convenience here, you can just save it on your desktop.
Before next step is just to check out an example and some important files that we will use.
Copy "mathlink.h" into /usr/include
Copy "mathlink.framework" into /Library/Frameworks
Copy libMLi3.a to /usr/lib or you can just leave it here.
Open "factor.m" file and copy everything inside and paste it into the main.c in your project. You should have everything in the original main.c gets replaced by the new conent.
You probably would see an error message about missing mathlink.h. You just need to add them aforementioned filed into the build path
Add /usr/include. Click mathlink project -> Targets/mathlink and search for "Other C Flags". Then you can add "-I /usr/include"
add libMLi3.a. If you haven't not move this file, you can just drag it into the project or drag it into build phase ( the latter just copy the path instead of file). Click mathlink project -> Targets/mathlink and choose "Build Phases".
Finally you need to modify the "Other Linker Flags" in "Build Settings"
Now if you run the project, you should see the "Build Success". In the target output, you will have a prompt in the Target Output dialog (bottom right)
You might wonder that your prompt asking you to create a link instead of input. This is because XCode just launchs the binary (Target file: mathlink) directly without a specific linkname so it is waiting for you to connect it to a running Mathematica kernel. To set a default link, you can just add some argument vector into XCode.
Stop the runtime and Click Product in the menu bar. Choose "Edit Scheme".
Choose "Run " -> Arguments Passed On Launch and add "-linkname /usr/local/bin/math". Click OK.
Now you can run this project again. In the prompt, you can just put a number and it will return the prime factors
Reply to this discussion
in reply to
Community posts can be styled and formatted using the
Tag limit exceeded
Note: Only the first five people you tag will receive an email notification; the other tagged names will appear as links to their profiles.
Add a file to this post
Follow this discussion
Be respectful. Review our
to understand your role and responsibilities.
Wolfram|Alpha Notebook Edition
Volume & Site Licensing
Enterprise Private Cloud
Service Plans Benefits
Wolfram Language Documentation
Wolfram Language Introductory Book
Get Started with Wolfram
Fast Introduction for Programmers
Fast Introduction for Math Students
Webinars & Training
Connected Devices Project
Wolfram Data Drop
Wolfram + Raspberry Pi
. All rights reserved.
Learn how »