rsmenon / MATLink

Communicate with MATLAB from Mathematica
matlink.org
68 stars 14 forks source link

Compilation with Mathematica 13.0.0 and MATLAB R2018a in Ubuntu 20.04.4 #115

Closed apozas closed 2 years ago

apozas commented 2 years ago

I am facing issues when trying to run MATLink between Mathematica 13.0.0 and MATLAB R2018a in Ubuntu 20.04.4. The problem is described in this StackExchange post, but I am reproducing it here with more details:

What is happening

After unzipping MATLink in the folder opened by SystemOpen@FileNameJoin[{$UserBaseDirectory, "Applications"}], running

Needs["MATLink`"]
OpenMATLAB[]

produces the following output: Automatically compiling the MATLink Engine has failed. See http://matlink.org/troubleshooting/, then try to compile it manually and ensure that the path to the MATLAB directory is set correctly in the makefile.

System specifications

I am running Ubuntu 20.04.4, 64-bit. which math returns /usr/local/bin/math (which itself is a symlink to /usr/local/Wolfram/Mathematica/13.0/Executables/math, which matlab returns /usr/local/MATLAB/R2018a/bin/matlab, and g++ -v returns gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1), although as I described in the StackExchange post I also tried g++ version 6.4.0 (the minimum version for MATLAB R2018a is 6.3.0, but I was unable to find it).

The output of MATLink`Developer`GetInfo[] is the following:

MATLink 1.1 for Unix (Fri 15 Aug 2014)

13.0.0 for Linux x86 (64-bit) (December 3, 2021)

csh:
/bin/csh

g++:
/usr/bin/g++

MATLAB:
/usr/local/MATLAB/R2018a/bin

libuuid:
    libuuid.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libuuid.so.1
    libuuid.so.1 (libc6) => /lib/i386-linux-gnu/libuuid.so.1
    libuuid.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libuuid.so

System PATH:
/usr/local/Wolfram/Mathematica/13.0/Executables
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/usr/local/MATLAB/R2018a/bin
/snap/bin
/home/apozas/mosek/8/tools/platform/linux64x86/bin

What else I have tried

I tried compiling manually the engine, following the instructions on the website. Running make -f Makefile.lin64 produces the output

g++ -O -Wall -I/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions -I/usr/local/MATLAB/R2018a/bin/../extern/include -L/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions -L/usr/local/MATLAB/R2018a/bin/../bin/glnxa64 menginetm.cpp mengine.cpp set.cpp get.cpp main.cpp -Wl,-rpath-link,/usr/local/MATLAB/R2018a/bin/../bin/glnxa64/ -DMLINTERFACE=3 -lML64i3 -luuid -lmx -leng -o mengine
In file included from menginetm.cpp:9:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:22: error: stray ‘\’ in program
  116 | /*\ syntax\ error\ */\ )
      |                      ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:24: error: expected unqualified-id before ‘)’ token
  116 | /*\ syntax\ error\ */\ )
      |                        ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:544:2: error: ‘wint’ does not name a type; did you mean ‘_wint’?
  544 |  wint low, hi;
      |  ^~~~
      |  _wint
In file included from mlp.h:11,
                 from mengine.h:11,
                 from mengine.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:22: error: stray ‘\’ in program
  116 | /*\ syntax\ error\ */\ )
      |                      ^
In file included from mlp.h:11,
                 from mengine.h:11,
                 from mengine.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:24: error: expected unqualified-id before ‘)’ token
  116 | /*\ syntax\ error\ */\ )
      |                        ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:544:2: error: ‘wint’ does not name a type; did you mean ‘_wint’?
  544 |  wint low, hi;
      |  ^~~~
      |  _wint
In file included from mlp.h:11,
                 from mengine.h:11,
                 from set.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:22: error: stray ‘\’ in program
  116 | /*\ syntax\ error\ */\ )
      |                      ^
In file included from mlp.h:11,
                 from mengine.h:11,
                 from set.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:24: error: expected unqualified-id before ‘)’ token
  116 | /*\ syntax\ error\ */\ )
      |                        ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:544:2: error: ‘wint’ does not name a type; did you mean ‘_wint’?
  544 |  wint low, hi;
      |  ^~~~
      |  _wint
In file included from /usr/local/MATLAB/R2018a/bin/../extern/include/engine.h:34,
                 from mengine.h:13,
                 from set.cpp:8:
set.cpp: In function ‘void eng_make_ComplexArray(double*, int, double*, int, int*, int)’:
/usr/local/MATLAB/R2018a/bin/../extern/include/matrix.h:608:17: error: ‘mxGetPiIsDeprecated’ was not declared in this scope
  608 | #define mxGetPi mxGetPiIsDeprecated
      |                 ^~~~~~~~~~~~~~~~~~~
set.cpp:95:32: note: in expansion of macro ‘mxGetPi’
   95 |     std::copy(imag, imag+ilen, mxGetPi(var));
      |                                ^~~~~~~
set.cpp: In function ‘void eng_make_SparseComplex(int*, int, int*, int, double*, int, double*, int, int, int)’:
/usr/local/MATLAB/R2018a/bin/../extern/include/matrix.h:608:17: error: ‘mxGetPiIsDeprecated’ was not declared in this scope
  608 | #define mxGetPi mxGetPiIsDeprecated
      |                 ^~~~~~~~~~~~~~~~~~~
set.cpp:116:32: note: in expansion of macro ‘mxGetPi’
  116 |     std::copy(imag, imag+ilen, mxGetPi(var));
      |                                ^~~~~~~
set.cpp: In function ‘void eng_make_String(const short unsigned int*, int)’:
set.cpp:160:28: warning: narrowing conversion of ‘len’ from ‘int’ to ‘mwSize’ {aka ‘long unsigned int’} [-Wnarrowing]
  160 |     mwSize mbDims[2] = {1, len};
      |                            ^~~
In file included from /usr/include/c++/9/cassert:44,
                 from set.cpp:13:
set.cpp: In function ‘void eng_make_Struct()’:
set.cpp:192:39: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
  192 |     assert(mxGetNumberOfElements(var) == len);
In file included from mlp.h:11,
                 from mengine.h:11,
                 from get.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:22: error: stray ‘\’ in program
  116 | /*\ syntax\ error\ */\ )
      |                      ^
In file included from mlp.h:11,
                 from mengine.h:11,
                 from get.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:24: error: expected unqualified-id before ‘)’ token
  116 | /*\ syntax\ error\ */\ )
      |                        ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:544:2: error: ‘wint’ does not name a type; did you mean ‘_wint’?
  544 |  wint low, hi;
      |  ^~~~
      |  _wint
In file included from /usr/local/MATLAB/R2018a/bin/../extern/include/engine.h:34,
                 from mengine.h:13,
                 from get.cpp:8:
get.cpp: In function ‘void toMma(const mxArray*, MLINK)’:
/usr/local/MATLAB/R2018a/bin/../extern/include/matrix.h:608:17: error: ‘mxGetPiIsDeprecated’ was not declared in this scope
  608 | #define mxGetPi mxGetPiIsDeprecated
      |                 ^~~~~~~~~~~~~~~~~~~
get.cpp:95:43: note: in expansion of macro ‘mxGetPi’
   95 |                     MLPutReal64List(link, mxGetPi(var), nnz); break;
      |                                           ^~~~~~~
/usr/local/MATLAB/R2018a/bin/../extern/include/matrix.h:593:23: error: ‘mxGetImagDataIsDeprecated’ was not declared in this scope
  593 | #define mxGetImagData mxGetImagDataIsDeprecated
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~
get.cpp:97:53: note: in expansion of macro ‘mxGetImagData’
   97 |                     MLPutReal32List(link, (float *) mxGetImagData(var), nnz); break;
      |                                                     ^~~~~~~~~~~~~
/usr/local/MATLAB/R2018a/bin/../extern/include/matrix.h:608:17: error: ‘mxGetPiIsDeprecated’ was not declared in this scope
  608 | #define mxGetPi mxGetPiIsDeprecated
      |                 ^~~~~~~~~~~~~~~~~~~
get.cpp:133:44: note: in expansion of macro ‘mxGetPi’
  133 |                     MLPutReal64Array(link, mxGetPi(var), mmDims, NULL, depth); break;
      |                                            ^~~~~~~
/usr/local/MATLAB/R2018a/bin/../extern/include/matrix.h:593:23: error: ‘mxGetImagDataIsDeprecated’ was not declared in this scope
  593 | #define mxGetImagData mxGetImagDataIsDeprecated
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~
get.cpp:135:54: note: in expansion of macro ‘mxGetImagData’
  135 |                     MLPutReal32Array(link, (float *) mxGetImagData(var), mmDims, NULL, depth); break;
      |                                                      ^~~~~~~~~~~~~
In file included from mlp.h:11,
                 from mengine.h:11,
                 from main.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:22: error: stray ‘\’ in program
  116 | /*\ syntax\ error\ */\ )
      |                      ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:24: error: expected unqualified-id before ‘)’ token
  116 | /*\ syntax\ error\ */\ )
      |                        ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:544:2: error: ‘wint’ does not name a type; did you mean ‘_wint’?
  544 |  wint low, hi;
      |  ^~~~
      |  _wint
make: *** [Makefile.lin64:21: mengine] Error 1

And running it as superuser does not seem to make a difference. It was suggested in different places that I edited Makefile.lin64 and added the flag -DMX_COMPAT_32 to CFLAGS. Upon doing so, running make -f Makefile.lin64 produces the output:

g++ -O -Wall -DMX_COMPAT_32 -I/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions -I/usr/local/MATLAB/R2018a/bin/../extern/include -L/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions -L/usr/local/MATLAB/R2018a/bin/../bin/glnxa64 menginetm.cpp mengine.cpp set.cpp get.cpp main.cpp -Wl,-rpath-link,/usr/local/MATLAB/R2018a/bin/../bin/glnxa64/ -DMLINTERFACE=3 -lML64i3 -luuid -lmx -leng -o mengine
In file included from menginetm.cpp:9:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:22: error: stray ‘\’ in program
  116 | /*\ syntax\ error\ */\ )
      |                      ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:24: error: expected unqualified-id before ‘)’ token
  116 | /*\ syntax\ error\ */\ )
      |                        ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:544:2: error: ‘wint’ does not name a type; did you mean ‘_wint’?
  544 |  wint low, hi;
      |  ^~~~
      |  _wint
In file included from mlp.h:11,
                 from mengine.h:11,
                 from mengine.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:22: error: stray ‘\’ in program
  116 | /*\ syntax\ error\ */\ )
      |                      ^
In file included from mlp.h:11,
                 from mengine.h:11,
                 from mengine.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:24: error: expected unqualified-id before ‘)’ token
  116 | /*\ syntax\ error\ */\ )
      |                        ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:544:2: error: ‘wint’ does not name a type; did you mean ‘_wint’?
  544 |  wint low, hi;
      |  ^~~~
      |  _wint
In file included from mlp.h:11,
                 from mengine.h:11,
                 from set.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:22: error: stray ‘\’ in program
  116 | /*\ syntax\ error\ */\ )
      |                      ^
In file included from mlp.h:11,
                 from mengine.h:11,
                 from set.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:24: error: expected unqualified-id before ‘)’ token
  116 | /*\ syntax\ error\ */\ )
      |                        ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:544:2: error: ‘wint’ does not name a type; did you mean ‘_wint’?
  544 |  wint low, hi;
      |  ^~~~
      |  _wint
In file included from /usr/include/c++/9/cassert:44,
                 from set.cpp:13:
set.cpp: In function ‘void eng_make_Struct()’:
set.cpp:192:39: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
  192 |     assert(mxGetNumberOfElements(var) == len);
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
In file included from mlp.h:11,
                 from mengine.h:11,
                 from get.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:22: error: stray ‘\’ in program
  116 | /*\ syntax\ error\ */\ )
      |                      ^
In file included from mlp.h:11,
                 from mengine.h:11,
                 from get.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:24: error: expected unqualified-id before ‘)’ token
  116 | /*\ syntax\ error\ */\ )
      |                        ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:544:2: error: ‘wint’ does not name a type; did you mean ‘_wint’?
  544 |  wint low, hi;
      |  ^~~~
      |  _wint
In file included from mlp.h:11,
                 from mengine.h:11,
                 from main.cpp:8:
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:22: error: stray ‘\’ in program
  116 | /*\ syntax\ error\ */\ )
      |                      ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:116:24: error: expected unqualified-id before ‘)’ token
  116 | /*\ syntax\ error\ */\ )
      |                        ^
/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/mathlink.h:544:2: error: ‘wint’ does not name a type; did you mean ‘_wint’?
  544 |  wint low, hi;
      |  ^~~~
      |  _wint
make: *** [Makefile.lin64:21: mengine] Error 1

Any help in solving this issue would be very much appreciated. Thank you

szhorvat commented 2 years ago

Edit Makefile.lin64 and:

Tell us if it works, or post the new error message please.

apozas commented 2 years ago

It worked! Thank you for such a quick and effective answer. Now OpenMATLAB[] and simple problems like MEvaluate["2+2"] work without any apparent problem. For completeness, this is the output of running make -f Makefile.lin64 with the proposed changes implemented:

g++ -O -Wall -DMX_COMPAT_32 -I/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions -I/usr/local/MATLAB/R2018a/bin/../extern/include -L/usr/local/Wolfram/Mathematica/13.0/Executables/../SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions -L/usr/local/MATLAB/R2018a/bin/../bin/glnxa64 menginetm.cpp mengine.cpp set.cpp get.cpp main.cpp -Wl,-rpath-link,/usr/local/MATLAB/R2018a/bin/../bin/glnxa64/ -lML64i4 -luuid -lmx -leng -o mengine
In file included from /usr/include/c++/9/cassert:44,
                 from set.cpp:13:
set.cpp: In function ‘void eng_make_Struct()’:
set.cpp:192:39: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
  192 |     assert(mxGetNumberOfElements(var) == len);
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~

But, as I said, it works. Thank you very much! I am closing the issue and writing this solution in the StackExchange post. However, if you decide to write it yourself later, I will happily accept yours as the correct answer.