Compiling mex/cpp on linux cluster with g++ 4.7

5 views (last 30 days)
phil
phil on 6 Oct 2015
Edited: Vamsi Karthik on 27 Sep 2016
Hi, I running a simulation on our ubuntu/debian x86_64 cluster and for that need to compile a mex script. As there is only g++/gcc 4.9 installed, i have downloaded g++-4.7 and am running the script via
mex CXX='path/to/g++/bin/g++-4.7 path/to/somefile.cpp
for this i get the response
Building with 'g++'.
Warning: You are using gcc version '4.9.2'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported
compilers see: http://www.mathworks.com/support/compilers/current_release.
Warning: You are using gcc version '4.9.2-10)'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently
supported compilers see: http://www.mathworks.com/support/compilers/current_release.
Error using mex
path/to/g++/bin/../lib/gcc/x86_64-linux-gnu/4.7/cc1plus: error while loading shared libraries: libmpc.so.2: cannot open shared object file: No
such file or directory
why am i getting warnings in this process for using an old gcc version and why does it not build. Building without giving CXX gives the same warnings but compiles successfully. Unfortunately that compiled script does not run and returns another error:
Invalid MEX-file 'some/mex/file.mexa64': /opt/matlab2014b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version
`GLIBCXX_3.4.20' not found (required by some/mex/file.mexa64)
  1 Comment
Vamsi  Karthik
Vamsi Karthik on 27 Sep 2016
Edited: Vamsi Karthik on 27 Sep 2016
Hello,
Install the required gcc version (in your case 4.7) and use the following commands if you are in ubuntu
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7
sudo update-alternatives --config gcc
Hope it helps, It worked for me.

Sign in to comment.

Answers (1)

Rohit Kudva
Rohit Kudva on 20 Oct 2015
Hi Phil,
I understand that you are unable to compile your CPP file using GCC compiler version 4.7 which is supported by MATLAB R2014b. You can try one of the following solutions:
1) Execute the following command on the MATLAB command prompt
>> mex -setup C++
It should list all the available MATLAB compatible compilers for compiling C++ code. You can then select the GCC-4.7 compiler from the list and then execute the following
>> mex path/to/somefile.cpp
2) If you are unable to view the GCC-4.7 compiler in the list of available compilers, the suggested workaround to override the default compiler is to use the GCC option. Please use the GCC option along with the mex command to point at a supported compiler version. Also make use of the verbose option (-v flag) in order to view the current settings of GCC, and confirm the changes made.
>> mex -v GCC='path/to/g++/bin/g++-4.7' path/to/somefile.cpp
I hope either of the above workarounds resolves the issue.
Regards,
Rohit

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!