# Missing _MLDisownDoubleArray from libMLi4.a building MathLink with MEX

Unfortunately, when I compile

mex(['-I', 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
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

• "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. Jan 19 '18 at 8:30
• Can you link to the program you are trying to compile (preferably link to its installation/compilation instructions)? Feb 18 '18 at 16:54

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.
• @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++. Jan 22 '18 at 23:49
• 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++. Jan 24 '18 at 10:11