Re: MathLink
- To: mathgroup at smc.vnet.net
- Subject: [mg25994] Re: [mg25966] MathLink
- From: John Fultz <jfultz at wolfram.com>
- Date: Wed, 15 Nov 2000 02:09:44 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
You don't have the proper quoting here. The command-line parser won't be able to tell that the spaces in the pathname aren't actually argument delimiters. Throw a \" before and after the pathname to the kernel. Otherwise, it tries to execute "C:\\Program", and then gets confused when it doesn't find C:\Program.exe. Having not found the program, it will, of course, ask you where it is. For example, "-linkname \"C:\\Program Files\\Wolfram Research\\Mathematica\\4.0\\MathKernel\" -linkmode launch" A further problem comes in that MathKernel really should be launched with the '-mathlink' argument. But that would *also* need to be quoted, and now things start to get messy. Well, there are two solutions. The easy solution is to use a version of the filename which doesn't have spaces...for example, we could exploit the short filenames on Windows to do... "-linkname \"C:\\Progra~1\\Wolfra~1\\Mathematica\\4.0\\MathKernel -mathlink\" -linkmode launch" The better solution is to use another form of MLOpen which allows you to pass in string arrays such as MLOpenArgV. Here's some sample code which I didn't actually try compiling, but ought to point you in the right direction. // Warning...I didn't actually compile this, so there may be typos, but it // should give you the idea. const char * mlargs[4] = {"-linkname", "C:\\Program Files\\Wolfram Research\\Mathematica\\4.0\\MathKernel -mathlink", "-linkmode", "launch"}; long err; MLINK link; MLEnvironment env = MLInitialize(NULL); link = MLOpenArgV(env, mlargs, mlargs+4, &err); // or you could do the slightly more sensible, but undocumented // call below... link = MLOpenInEnv(env, mlargs, 4, &err); Sincerely, John Fultz jfultz at wolfram.com User Interface Group Wolfram Research, Inc. > I am trying to call a mathematica function from my C program (Win98). I use > the enclosed function to > start the kernel. The program works fine but I cannot get rid of the file > select windows which pops up > and ask me to select a mathlink program. I would be grateful for any > suggestions as to how to fix this > problem. > Thanks, > Mirek Latka > > > void init_and_openlink() > { > long err; > > ep = MLInitialize( (MLParametersPointer)0); > if( ep == (MLENV)0) exit(1); > atexit( deinit); > > lp=MLOpenString(ep,"-linkname C:\\Program Files\\Wolfram > Research\\Mathematica\\4.0\\MathKernel.exe -linkmode launch",&err); > if(lp == (MLINK)0) exit(2); > atexit( closelink); > > }