Question about MathLink and .NET/Link with Mono on Mac OS X and Linux
- To: mathgroup at smc.vnet.net
- Subject: [mg97004] Question about MathLink and .NET/Link with Mono on Mac OS X and Linux
- From: Cornelis Swanepoel <crs at cygnusblack.co.uk>
- Date: Sun, 1 Mar 2009 04:58:50 -0500 (EST)
hi there, I would like to be able to interact between the Mono runtime and Mathematica but I am running into problems regarding the MathLink libMLi3 library. I have the following setup: OS X --> 10.5.6 Mathematica version string --> 7.0 for Mac OS X x86 (64-bit) (November 11, 2008) Mono version string --> Mono JIT compiler version 2.2 (tarball Fri Jan 9 10:45:07 MST 2009) ... Architecture: x86 On searching the MathGroup archive I found a message indicating that there exists experimental support for Mono on Linux in .NET/Link since ver 5.2 of Mathematica as long as the mono command is in your $PATH (yes in my case). ( Oct 2005 [msg61190] ) and as NETLink was placed in $InstallationDirectory/SystemFiles/ Links/, next to JLink, by the Mathematica for OS X installer, I expected things to work out of the box, like JLink does. Following the procedure set out in the NETLink tutorial I typed into a notebook with an active kernel: Needs["NETLink`"] $Packages and received the following output: {"NETLink`", "ResourceLocator`", "DocumentationSearch`", "JLink`", \ "PacletManager`", "WebServices`", "System`", "Global`"} However, when trying to launch the runtime via InstallNET[] it fails with: LinkOpen::linke : Could not find MathLink executable. >> InstallNET::fail : A link to the .NET runtime could not be established. >> $Failed This happens even when I SetDirectory to $InstallationDirectory/ SystemFiles/Links/MathLink When trying to launch the mathlink executable manually from the shell it fails with: -bash: ./mathlink: cannot execute binary file I am still very much of a Mathematica noob but I went and opened the InstallNET.m source file and found another indicator that this should be possible, line 176,7 If[!osIsWindows[], \ netlinkPath = "mono " ... The source in this file seems to indicate that the key to getting this working lies in the netLinkExe file, InstallableNET.exe, which is next to NETLink.m. I tried to launch this file on the Mono CLR and received the following error message: rools@roolsMBP:~/Applications/Mathematica.app/SystemFiles/Links/ NETLink $mono InstallableNET.exe Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for Wolfram.NETLink.Internal.NativeLink ---> System.DllNotFoundException: libML32i3.so at (wrapper managed-to-native) Wolfram.NETLink.Internal.UnixMathLinkAPIProvider:MLBegin (intptr) at Wolfram.NETLink.Internal.UnixMathLinkAPIProvider.extMLBegin (IntPtr zero) [0x00000] at Wolfram.NETLink.Internal.NativeLink..cctor () [0x00000] --- End of inner exception stack trace --- at Wolfram.NETLink.MathLinkFactory.createMathLink0 (System.String cmdLine, System.String[] argv) [0x00000] at Wolfram.NETLink.MathLinkFactory.CreateMathLink (System.String[] argv) [0x00000] at Wolfram.NETLink.MathLinkFactory.createKernelLink0 (System.String cmdLine, System.String[] argv) [0x00000] at Wolfram.NETLink.MathLinkFactory.CreateKernelLink (System.String[] argv) [0x00000] at Wolfram.NETLink.InstallableNET.Main (System.String[] args) [0x00000] The problem is that the UnixMathLinkAPIProvider is called and not the MacMathLinkAPIProvider. Because of this it is trying to find the libML32i3.so shared library. Mathematica for OS X does not have an OS X dynamic library, i.e. libML32i3.dylib - the equivalent of the Linux shared library. Only a static library, libMLi3.a which resides in $InstallationDirectory/SystemFiles/Links/MathLink/DeveloperKit/ CompilerAdditions for which I created a link in /usr/local/lib I'm wondering if there is a way to change things to load the MacMathLinkAPIProvider instead. Obviously the .cs source files are available but this is baked into InstallableNET.exe And if I could, would I be able to do the DllImport on libMLi3.a? Currently the MacMathLinkAPIProvider.cs file declares the library [DllImport("mathlink")] compared to the Unix provider's [DllImport("libML32i3.so")] Any advice, thoughts and ideas will be greatly appreciated. Cornelis