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:
- Win7 x64
- Mathematica 9
- DLL compiled with MinGW x64, using an import library for ml64i3.dll generated with gendef/dlltool (see http://forums.wolfram.com/mathgroup/archive/2012/Jun/msg00323.html)
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.
long double
, amonst other things. $\endgroup$