Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a compiled program with MathLink. I want to use it from other C program, without Mathematica being involved at all. If i create my program with MathLink and connect to this external program, than i get number packets with number of functions: DefineExternal ["funcname[]" , "{ }" , 89 ] that registers these functions as external in Mathematica. How could i, from my C programm, call analog of Mathematica CallPacket[89,{}] function to call "funcname". Sending directly MLPutFunction(lp, "funcname") to this external application does not seems to be working, as, i suppose, it is intended to be used only for communication from external program with Mathematica, or?

share|improve this question
Now that is an absolutely fascinating question. – rcollyer Aug 15 '12 at 0:58
I must admit I was very unclear as to the meaning of your question until I saw your comment on the corresponding question on SO. Anyway, you cannot use MLPutFunction(lp, "funcname")--functions must be called by ordinal as MathLink programs don't have access to the Mathematica interpreter. Instead use MLPutFunction(lp, "CallPacket", nargs+1); MLPutInteger(lp, ord); /* put any arguments on the link here */ MLEndPacket(lp);. See the book MathLink: Network Programming with Mathematica by Chikara Miyaji and Paul Abbott for more information. – Oleksandr R. Aug 15 '12 at 9:52
Sorry--the arguments should be in a List, not given as a sequence. (That's why this is just a comment: no time to give a properly debugged answer now. I'm sure you'll be able to figure it out for yourself--and when you get a working solution, feel free to self-answer.) – Oleksandr R. Aug 15 '12 at 10:16
up vote 6 down vote accepted

Thank you very much Oleksandr, it works. There should be empty List even when no arguments.

MLPutFunction(lp, "CallPacket", 2);
MLPutInteger(lp, 89);
MLPutFunction(lp, "List", 0);

MLGetReal(lp, &dp);  //return value
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.