0
$\begingroup$

I have written a console application on Visual Studio C++ as below

#include <mathlink.h> //mathlink header
#include <stdio.h> //standard io header
#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
    /* initialising variables */
    MLENV env = (MLENV)0;
    MLINK link = (MLINK)0;
    int errno;
    int packet;
    int input;

    /* initialises MathLink environemnt object */
    env = MLInitialize(0);

    /* links the program to the MathKernel */
    link = MLOpenString(env, "-linkmode launch -linkname 'C:\\Program Files\\Wolfram Research\\Mathematica\\9.0\\math.exe'", &errno);
    MLActivate(link); //activates a MathLink connection with a mathlink program

    /* send 42+137 using the full form Plus[42, 137] */
    MLPutFunction(link, "Plus", 2); //integer 2 signifying 2 arguments passed to the MathLink program
    cout << "Enter the first integer: ";
    cin >> input;
    MLPutInteger(link, input); //puts the integer to the MathLink connection
    cout << "Enter the second integer: ";
    cin >> input;
    MLPutInteger(link, input); //puts the integer to the MathLink connection
    MLEndPacket(link); //indicates that current expression is complete and ready to be sent

    /* get packets until we find a ReturnPacket or error */
    while ((packet = MLNextPacket(link)) && packet != RETURNPKT) MLNewPacket(link);

    /* once the results is returned */
    if (MLError(link)) printf("\nError Has Occured!\n");    //if an error is returned
    else {                                                  //if an integer is returned
        int result;
        MLGetInteger(link, &result); //we know that the result is an integer in this case
        printf("\nResult: %d\n", result);
    }

    printf("\nPress Enter to Exit...");
    getchar(); //holds the console till users presses enter
    getchar(); //holds the console till users presses enter
    return 0;
}

Everything works fine. However, this uses MathLink, linking to math.exe. If I am to use the executable file of this code in a computer without Mathematica, it wouldnt work.

My solution explorer looks like:

enter image description here

Any advise on how to compile so that the file can be used in a computer without mathematica installed?

$\endgroup$
5
  • 2
    $\begingroup$ What you are asking for is not possible. You cannot call Mathematica from your program on a computer where Mathematica is not installed. $\endgroup$ Commented Jan 17, 2014 at 16:06
  • $\begingroup$ @Szabolcs This has been asked before; would you help me find the duplicate(s)? $\endgroup$ Commented Jan 17, 2014 at 16:15
  • 1
    $\begingroup$ @Mr.Wizard This and this are related. $\endgroup$ Commented Jan 17, 2014 at 16:17
  • 1
    $\begingroup$ @Szabolcs strictly speaking I suppose that one could use MathLink to call a kernel running on a different computer. But, I agree, this probably isn't the use case the OP had in mind. $\endgroup$ Commented Jan 17, 2014 at 16:26
  • 1
    $\begingroup$ @OleksandrR. Good point. Maybe things will change with the Wolfram Cloud wolframcloud.com (about which I know nothing except this URL). $\endgroup$ Commented Jan 17, 2014 at 16:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.