1
$\begingroup$

I'm trying to build MathLink on a Mac using Mex, according to the instructions included in the MathLink download.

Unfortunately, when I compile

mex(['-I', Mathematica_path, 'Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions'], ...
['-L', Mathematica_path, 'Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions'], ...
['-l', 'MLi4'], ...
['-I', Mathematica_path, 'IncludeFiles/C'], '-v', ...
'math.c');

I get the error

Error using mex
Undefined symbols for architecture x86_64:
  "_MLDisownDoubleArray", referenced from:
  _mexFunction in math.o
  "_MLDisownString", referenced from:
  _mexFunction in math.o
  _WaitForReturnPacket in math.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It seems that libMLi4.a does not contain the DisownDoubleArray or DisownString functions, which is causing the MathLink to fail to compile. Which library should I use to find those functions? (Note I'm using these as a part of Ayonga's FROST toolkit in Matlab, so I think I actually need MathLink, not WSTP) Thanks!

I'm using Mac OS X 10, Matlab R2015b, and Mathematica 11.2.0

$\endgroup$
  • $\begingroup$ "I'm trying to build MathLink" You are not building MathLink. The MathLink library is already built. You are trying to build a program that uses MathLink, and was written for an earlier interface level than what you are compiling with. $\endgroup$ – Szabolcs Jan 19 '18 at 8:30
  • $\begingroup$ Can you link to the program you are trying to compile (preferably link to its installation/compilation instructions)? $\endgroup$ – Szabolcs Feb 18 '18 at 16:54
1
$\begingroup$

You are compiling a program written for an earlier MathLink interface level (probably 3), and you are linking against interface level 4.

Make sure the macro MLINTERFACE is defined to 3 when you compile, and link against MLi3 instead of MLi4.

Actually, I believe on OS X the normal way would be to use the -framework mathlink option instead of -lMLi4. But I do not know how to select a specific framework version.

$\endgroup$
  • $\begingroup$ Thanks for the clarification, I'm trying to compile the Mathematica Symbolic Toolbox for Matlab (which uses MathLink) using mex. Unfortunately, it was last updated in 2004, so a lot of things have probably changed. I have a couple questions: how do you change MLINTERFACE? I don't think it's in the mex settings file, nor is it in math.c. Also, MLi3 seems to be a C++ library, whereas MLi4 is a C library (and the file I'm using is in c) $\endgroup$ – rsnorunt Jan 22 '18 at 23:37
  • $\begingroup$ @rsnorunt Pass the option -DMLINTERFACE=3 to the compiler. How to do that from within MATLAB, I don't know. You need to link against MLi3 if the program uses MathLink interface version 3, which seems to be the case here. I do not understand why you think this has anything to do with C vs C++. $\endgroup$ – Szabolcs Jan 22 '18 at 23:49
  • $\begingroup$ Hmmm, I tried passing -DMLINTERFACE=3 into both the compiler flags and the library flags, and neither seemed to do anything. When I tried switching to MLi3, I got dozens of errors instead of 2. I also tried adding -framework mathlink to the library flags, and it said that I didn't have that framework. $\endgroup$ – rsnorunt Jan 24 '18 at 6:32
  • $\begingroup$ I believe your compiler command line should look like -DMLINTERFACE=3 -lMLi3 -framework Foundation -lstdc++ , plus -L and -I for library and include paths, plus the stuff needed for MATLAB, plus the source files and output name. If you get errors, please show the full command line, as well as the first few (and most relevant) errors. This is assuming that you are compiling as C, not C++. $\endgroup$ – Szabolcs Jan 24 '18 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.