// To compile: mcc -Wno-long-double -o mltest mltest.c // To run: ./mltest -linkname '/Applications/Mathematica\ 4.2.app/Contents/MacOS/MathKernel -mathlink' -linkmode launch // /Applications/Mathematica 4.2.app/AddOns/MathLink/DeveloperKit/Darwin/Documentation/English/DeveloperGuide.nb // http://forums.wolfram.com/mathgroup/archive/1999/Jan/msg00225.html // http://library.wolfram.com/infocenter/TechNotes/281 PS graphics w/ ML // 2.12 MathLink // On page 29 of 43 of ML_Tut.pdf (ps?) // MLPutFunction(lp, "EvaluatePacket", 1); // MLPutfunction(lp, "ToExpression", 1); // MLPutString(lp, "3 + 3"); // MLEndPacket(lp); #include #include "mathlink.h" // put mathlink.h in /usr/include // any .a or .lib files go in /usr/lib int main(int argc, char *argv[]) { int i, j, sum; MLINK lp; int pkt; MLEnvironment env; printf("Enter two integers (separated by a space) :\n\t"); scanf( "%d %d", &i, &j); env = MLInitialize(NULL); if (env == NULL) return 1; lp = MLOpen(argc, argv); if (lp == NULL) return 1; MLPutFunction(lp, "Plus", 2); MLPutInteger(lp, i); MLPutInteger(lp, j); MLEndPacket(lp); while (MLNextPacket(lp) != RETURNPKT) MLNewPacket(lp); MLGetInteger(lp, &sum); printf( "sum = %d\n", sum); MLClose(lp); MLDeinitialize(env); return 0; }