简体   繁体   中英

Choosing a default gcc/g++ compiler

Im running Matlab on linux (Elementary OS)
The problem im facing is that Matlab isnt compatible with the gcc compiler higher than 4.9.
Same question as: https://www.mathworks.com/matlabcentral/answers/348906-downgrading-gcc-g-for-use-with-mex
When I use "sudo apt get install gcc" 5.4 is automatically installed. When I remove 5.4, Matlab will not recognize 4.9 which I've installed. How do I get Matlab to recognize gcc/g++ 4.9 as my compiler?
I've also followed this but it didnt resolve the problem:
https://www.mathworks.com/matlabcentral/answers/137228-setup-mex-compiler-for-r2014a-for-linux#answer_263109
Any help would be greatly appreciated.

When I remove 5.4, Matlab will not recognize 4.9 which I've installed. How do I get Matlab to recognize gcc/g++ 4.9 as my compiler?

I use Ubuntu (from which you OS is derived) and have had a similar issue. Basically, you can use update-alternative to switch between gcc versions on your choice. Here is a link that explains how to do it.

Here is the documentation on update-alternative , if you need more in-depth knowledge of its functionalities.

Note that uninstalling the default gcc for your distro (5.4 in your case) is no longer required with this solution: you can switch back to it for you development when not using Matlab. You can even install more than two versions of gcc if needed.

Hope this solves your issue.

There is no reason to downgrade GCC for MATLAB.

The reason you run into issues on Linux is because MATLAB installs its own copies of the GCC libraries. If your MEX-files expect newer libraries, they'll fail. You can delete the GCC libraries that come with MATLAB, and it will use the newer ones on your system.

The libraries are at $(MATLABROOT)/sys/os/glnx86 for 32-bit MATLAB, and $(MATLABROOT)/sys/os/glnxa64 for 64-bit MATLAB. $(MATLABROOT) is the installation root for MATLAB.

The files in question are libgcc_s.so* , libstdc++.so* and libg2c.so* (or at least they used to be called like this, I don't have a Linux MATLAB installation here to double-check).

This trick worked for MATLAB 7.0, and still worked a month ago when I suggested this to a colleague.

I do recommend that you rename or move the files, so you can replace them if things go sour.

You will need to restart MATLAB after this change, of course.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM