Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
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. –  Oleksandr R. Jun 17 at 22:39

Your Answer


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

Browse other questions tagged or ask your own question.