I am trying to launch a MathLink from a 64bit C dll that I am building, using the following code:

#include "mathlink.h"

static MLENV ep = (MLENV)0;
static MLINK lp = (MLINK)0;

__declspec(dllexport) int __stdcall init()
  int err;
  char * argv[3];
  int success = 1;

  argv[0] = "-linklaunch";
  argv[1] = "-linkname";
  argv[2] = "'\"C:\\Program Files\\Wolfram Research\\Mathematica\\9.0\\MathKernel.exe\" -mathlink'";

  ep =  MLInitialize((char *)0);
  if(ep == (MLENV)0) success = 0;

  lp = MLOpenArgcArgv(ep, 3, argv, &err);

  if(lp == (MLINK)0) success = err;

  return success;

However, when calling this init() function, I always get the error code 34, indicating that the specified link protocol is unavailable. I tried specifying a link protocol (SharedMemory,Pipes,...) using the -linkprotocol argument for MLOpenArgcArgv(), but without any change.

Although the error code referes to the link protocol, I also tried different formats for the MathKernel.exe directory (e.g. \\\\ for backslashes, different quotes, ...), but nothing changed. Using 0 for argc and a null pointer for argv also doesn't change anything.

The necessary files for MathLink devices (mlshm64.mlp etc.) are all in their correct place (System32 folder for x64). I can also launch the MathKernel.exe from the command line without problems, and a different C program using MathLink which I'm accessing through the Install[] function in Mathematica is running fine on the same computer.

My system:

Any ideas what could be causing this error?

Edit I now got the same code running by compiling it in Visual Studio 2013 as a DLL and linking to the same MathLink DLL - still not sure why compiling in MinGW doesn't work though.

  • $\begingroup$ Good question. I don't know either. Could be slightly different ABIs between VS and MinGW? This should not really happen but there are subtle differences such as stack alignment and the length of a long double, amonst other things. $\endgroup$ Jun 17, 2014 at 22:39

1 Answer 1


I had the same problem on Win7 64bit with Mathematica 10.0. I have resolved it by removing -mathlink from the options sent to MathKernel, this means that WSOpenArgcArgv should receive the following list of options:

argv[4]="\"c:\\Program Files\\Wolfram Research\\Mathematica\\10.0\\MathKernel\"";

(or where your MathKernel stored)

PS This would be equivalent to running your program from the command line with the following options:

***.exe -linkmode launch -linkname "c:\Program Files\Wolfram Research\Mathematica\10.0\MathKernel"

and then simply passing argc, argv from main.

PS Of course written above relates to version 10.0 and current WSTP protocol, but necessary changes to run it in your case should be straightforward.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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