[localhost:~]$ cat * > /dev/ragfield

Thursday, April 2, 2009

Xcode project templates for MathLink applications

Setting up an Xcode project to build MathLink applications can be confusing and tedius. Therefore I have created Xcode project templates for MathLink applications.

Xcode project template installation

Download the templates here. Install the "MathLink" directory into "/Library/Application Support/Developer/Shared/Xcode/Project Templates/". After installation, when you create a new project in Xcode there will be a User Templates section that contains a MathLink subsection. Click on MathLink and find the two project templates.

Xcode project templates

The first project template is called C MathLink Program. Use it for the very simplest of applications where you want to implement a function (or a few functions) in C/C++ and call it directly from Mathematica. The project will create a single executable (.exe extension, yes, .exe, yes, on Mac).

Build the target and begin using it in Mathematica with the Install command.

Note: if Mathematica is installed in a different location than /Applications/Mathematica.app you will need to adjust the value of the user defined MATHEMATICA build setting in the target info window.

l = Install["~/Desktop/MyTest/build/Debug/MyTest.exe"]
LinkObject[/Users/schofield/Desktop/MyTest/build/Debug/MyTest.exe, 153, 9]
{MyTest[arg1_Integer, arg2_Real, arg3_String]}
MyTest[23, 4.5, "67"]

The second project template is called C MathLink Package. Use it for more complicated applications that require both C/C++ code and supporting Mathematica code. The support code goes into init.m.

1 comment:

Anonymous said...


Thank you very much for providing this template.

I have been struggling for >days on an XP machine with cygwin compiler to make it work.

It did work in the end but when I included socket connections to a server in the code it collapsed again. "Socket.h" is not compatible with the cygwin compiler settings needed for mathlink.

Now I will try sockets+mathlink in Xcode on the mac instead.

/Erik Wallén/Lund/Sweden