Simplest example (Add Two numbers)

Code Generation using MathCode

Simplest example

Load the MathCode system into Mathematica

Needs["MathCode`"]

This is needed if many notebooks run in a sequence

SetCurrentPackage["Global"]

Set Working Directory

SetDirectory[$MCRoot<>"/Demos/SimplestExample"];

Define a simple function

Typed definition

addtwo[Real a_,Real b_] -> Real := Module[{},a+b]

Evaluation in Mathematica

addtwo[2.,2.]

Generate C++ and Build Executables

BuildCode[]

Install the Mathlink Executable

InstallCode[];

Run some examples

addtwo[2.,2.]

Uninstall the code

UninstallCode[];

which will clean up things and terminate the MathLink process.

A glance at the Generated Code

!! Global.cc

CleanMathCodeFiles[Confirm -> False, CleanAllBut -> {}];