// To compile: mcc -Wno-long-double -o mltest2 mltest2.c // To run: ./mltest2 -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 i, j, sum; MLINK lp; int pkt; MLEnvironment env; char exp[256] = ""; int argc = 4; char *argv[5] = {"-linkname", " '/Applications/Mathematica 4.2.app/Contents/MacOS/MathKernel' -mathlink", "-linkmode", "launch", NULL}; printf("Enter in an expression: "); scanf("%s", exp); printf("Expression: %s\n", exp); env = MLInitialize(NULL); if (env == NULL) return 1; lp = MLOpen(argc, argv); if (lp == NULL) return 1; MLPutFunction(lp, "EvaluatePacket", 1); MLPutFunction(lp, "ToExpression", 1); MLPutString(lp, exp); MLEndPacket(lp); while (MLNextPacket(lp) != RETURNPKT) MLNewPacket(lp); MLGetInteger(lp, &sum); printf( "sum = %d\n", sum); MLClose(lp); MLDeinitialize(env); return 0; }