Group Abstract Group Abstract

Message Boards Message Boards

Changes in MathLink in Version 10 ?

POSTED BY: Frank Kampas
28 Replies
Posted 6 years ago
POSTED BY: TRAN ANH
Posted 5 years ago

Hi Tran. Did you ever solve this problem? I have the same issue.

Thanks,

POSTED BY: Chase Vaughn
Posted 10 years ago

Thanks, that worked! I added this directory to the PATH variable:

enter image description here

POSTED BY: nat dlsantos
Posted 10 years ago

Is this change from MathLink to "Wolfram Symbolic Transfer Protocol", the reason why I'm getting this error msg from Mathematica Link:

"MathLink libraries are not installed or outdated. Before linking, you must install Mathematica or the latest version of the MathLink libraries."

I have installed Mathematica 10..2.0.0, Excel 2013 32-bit and MLinkforExcel_3.6.0. Inside Excel. ExcelLink works fine inside Mathematica but MathLink is not accessible from inside Excel.

Any help would be appreciated. Thanks.MathLink error msg

POSTED BY: nat dlsantos

I might be completely wrong about this, but I seem to recall reading somewhere that the MathLink dynamic libraries (DLLs) used to be installed system-wide (in C:\Windows\system32 maybe?) before, but they are not since some recent version of Mathematica. You might try finding the libraries (presumably i3 versions, not i4; also make sure you copy the MathLink ones, not the WSTP one) in the Mathematica installation directory, and copying them next to the ExcelLink executable, if it has one.

I have never worked with ExcelLink, so I am not familiar with how it works.

To answer your question: I don't think this is because of the renaming to WSTP. The ML-prefixe version still ships with Mathematica and new versions of Mathematica are still compatible with old MathLink programs.

POSTED BY: Szabolcs Horvát

@SteveWilson

I'm right now investigating a bug report for MATLink on Linux. It appears that cycling a string through MATLink appends a zero character code at the end somehow, on Linux only (but not on OS X). I still haven't gotten to the bottom of the issue, and it is possible that I'm using the MathLink API incorrectly, but it looks more like a bug. I'm going to report it once I have had the time to create a minimal test case, but I wanted to give you advance warning.

enter image description here

The zero is likely appended when sending the string through MathLink the first time, not when receiving it back the Mma kernel.

The sending function is as simple as this:

void eng_make_String(const unsigned short *str, int len, int characters) {
    mwSize mbDims[2] = {1, len}; // use len, not characters, because no support for 4-byte characters in either Mma 9 or MATLAB
    mxArray *var = mxCreateCharArray(2, mbDims);
    std::copy(str, str+len, (unsigned short *) mxGetChars(var));
    returnHandle(var);
}

with template:

:Begin:
:Function:   eng_make_String
:Pattern:     engMakeString[string_]
:Arguments:     {string}
:ArgumentTypes: {UTF16String}
:ReturnType:    Manual
:End:

(You can actually ignore the guts of the functions, as it's MATLAB-specific code, but I thought a bit of context is always good. Also, I'm not sure it's still true that MathLink doesn't support UTF16 characters that need to be stored on 4 (not 2) bytes).

POSTED BY: Szabolcs Horvát
POSTED BY: Szabolcs Horvát
POSTED BY: Steve Wilson
POSTED BY: Szabolcs Horvát
POSTED BY: Steve Wilson
POSTED BY: Szabolcs Horvát
POSTED BY: Steve Wilson

Thank you for the clarification. It sounds like I should have been using USC2String form the beginning.

If Mathematica will get support for the full Unicode range in the future, that will be a very nice addition. I have needed characters from outside the basic multilingual plane in the past, while dealing with a Chinese character decomposition table. At that time I had to parse the surrogate pair manually.

POSTED BY: Szabolcs Horvát

Some LibraryLink code I wrote using MathLink to transfer data still works in Version 10, even though the functions have been deprecated. I imagine that means it won't work when Version 11 comes out.

POSTED BY: Frank Kampas

The LibraryLink interface that includes MathLink is very much tied to the interface used internally by the Kernel. If the Kernel is using MathLink interface 4, then the LibraryLink dlls need updated to support interface 4. The deprecated functions may continue to work for a time, however, as all things deprecated go, WRI may eventually remove those API functions from the interface altogether in a future release.

POSTED BY: Steve Wilson

Mprep should produce code that will work with the interface 3 version of the libraries. When building the code, if you want to link with the interface 3 library, you will need to define the preprocessor macro MLINTERFACE to 3, rather than letting it default to 4 in mathlink.h.

The linker error you are seeing that references uuid_parse is coming from a new requirement int he MathLink libraries to link with libuuid on Linux. You can use your Linux distribution's libuuid if you have one available or can install one from the distribution's package manager, or there is a libuuid in ${InstallationDirectory}/SystemFiles/Libraries/Linux-x86-64 suitable for use with the MathLink library.

POSTED BY: Steve Wilson

Thank you for the response!

Will Installable MathLink programs compiled with the default MLINTERFACE 4 and linked against ML64i4 still work with earlier Mathematica versions?

For example, let's assume that we have the source code for an installable MathLink program that worked with some older version of Mathematica. Now I re-run mprep and re-compile the program, linking it against ML64i4 or ML32i4. Will the resulting binary be usable with older versions of Mathematica, e.g. Mathematcia 8 or 9?


I know that I can #define MLINTERFACE 3 and link against ML64i3 for compatibility, but the question is whether this is necessary?

POSTED BY: Szabolcs Horvát

The programs compiled and linked with the interface 4 version of the library should indeed work with older versions of Mathematica. I assume at some point you will run into issues such as older operating systems that will eventually result in incompatibilities the further you go back with your Mathematica revisions, but if you can run the two copies of Mathematica on the same machine, then your newer binary should work with the older Kernel.

POSTED BY: Steve Wilson
POSTED BY: Szabolcs Horvát
  • The IntraProcess protocol is designed specifically for communication between threads in the same process. The protocol should be quite fast.

  • MathLink did receive performance enhancements in Version 10 with respect to string and symbol transfers. These enhancements are automatically enabled with communicating with another Version 10 MathLink library and disabled when communicating with an older version of the library.

POSTED BY: Steve Wilson

MathLink did receive performance enhancements in Version 10 with respect to string and symbol transfers. These enhancements are automatically enabled with communicating with another Version 10 MathLink library and disabled when communicating with an older version of the library.

Are these performance enhancements present even if I compile with -DMLINTERFACE=3 -lML64i3 (but using the libraries shipped with v10)?

In other words, does linking against libML64i4 have any benefits if I do not actually use any of the interface version 4 functions?

POSTED BY: Szabolcs Horvát
POSTED BY: Szabolcs Horvát
POSTED BY: Szabolcs Horvát
POSTED BY: Steve Wilson

This is very useful. I didn't find this page myself.

POSTED BY: Szabolcs Horvát

What does "the interface level has been bumped to 4" mean?

POSTED BY: Frank Kampas

I should have probably called it interface version 4, I'm not sure which is the official term used by WRI. It just means that the version number has been changed, which means that compatiblity with other interface versions is not guaranteed (new functions may be added, old functions removed or the calling syntax may change).

There is a seprate versioning for the public documented MathLink C interface and for the MathLink library. When the MathLink library gets a bugfix, the API to access it does not necessarily change. The API didn't change between Mathematica 8 and Mathematica 9, to my knowledge. But don't quote me on this, I'm not an expert on the topic.

POSTED BY: Szabolcs Horvát

The interface level has been bumped to 4. If you look in mathlink.h, you'll find a list of new functions and a list of removed functions (quoted at the end). The functions can be looked up in the documentation. There's probably more to say here, and I'm curious about the changes too.

I also noticed that parallel kernels launch much faster in version 10, which is likely due to MathLink changes.


The name chage, in my opinion, is pretty counterproductive. Renaming all API functions (used for engineering) just because of a marketing decision (!!) to rebrand the system is just wrong and I don't see how it could bring aything but trouble ...

Now Mathematica comes with two separate directories, one for MathLink and one for WSTP. The two look identical other than the renaming. One contains the libraries and header files with the ML prefixed functions, the other one has the WS prefixed functions.


    /*
     * Interface 4 adds the following exported functions:
     *
     * MLCreateLinkWithExternalProtocol
     * MLDoNotHandleSignalParameter
     * MLEnableLinkLock
     * MLFilterArgv
     * MLGetAvailableLinkProtocolNames
     * MLGetInteger8
     * MLGetInteger8Array
     * MLGetInteger8ArrayData
     * MLGetInteger8List
     * MLGetLinksFromEnvironment
     * MLGetNumberAsByteString
     * MLGetNumberAsString
     * MLGetNumberAsUCS2String
     * MLGetNumberAsUTF16String
     * MLGetNumberAsUTF32String
     * MLGetNumberAsUTF8String
     * MLHandleSignal
     * MLIsLinkLoopback
     * MLLinkEnvironment
     * MLLogFileNameForLink
     * MLLogStreamToFile
     * MLLowLevelDeviceName
     * MLPutInteger8
     * MLPutInteger8Array
     * MLPutInteger8ArrayData
     * MLPutInteger8List
     * MLPutRealNumberAsUCS2String
     * MLPutRealNumberAsUTF16String
     * MLPutRealNumberAsUTF32String
     * MLPutRealNumberAsUTF8String
     * MLReleaseInteger8Array
     * MLReleaseInteger8List
     * MLReleaseLinkProtocolNames
     * MLReleaseLinksFromEnvironment
     * MLReleaseLogFileNameForLink
     * MLReleaseLowLevelDeviceName
     * MLReleaseParameters
     * MLSetThreadSafeLinksParameter
     * MLStopHandlingSignal
     * MLStopLoggingStream
     * MLValid
     * MLWaitForLinkActivity
     * MLWaitForLinkActivityWithCallback
     *
     * Interface 4 removes the following API functions.
     *
     ....
     */
POSTED BY: Szabolcs Horvát
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard