Compilation of SPM on Linux¶
This page describes the compilation of SPM MEX files on Linux. It requires the installation of a C/C++ compiler and related tools (e.g. make). This can be done on Debian/Ubuntu by installing the build-essential package (sudo apt install build-essential).
Instructions¶
In a Terminal, from the src folder of your SPM installation, type:
This will generate *.mexa64 MEX files.
Troubleshooting¶
cannot find -lstdc++ error
If you get the error message “cannot find -lstdc++”, try installing the build-essential package using your package manager (i.e. sudo apt install build-essential on Ubuntu), or the specific libstdc++5 package (replacing 5 with the version of your system) with sudo apt-get install libstdc++5.
If, after the install of libstdc++5, the lstdc++ error persists, just add a symbolic link with:
and it should work. If not, see next.
For old versions of Ubuntu and MATLAB, have a look at these instructions.
Other problems with lstdc++
If you get the above error and cannot install libstdc++ (e.g. you do not have root/admin access), or if you get other problems such as “... versionGCC_4.2.0’ not found (required by /usr/lib64/libstdc++.so.6", then another option is to edit yourmexopts.shconfig file and delete or disable the-lstdc++compiler flags, for example simply use find-and-replace to delete all instances of-lstdc++`. SPM will compile properly without this.
It’s best to edit a local copy of mexopts.sh (the original is found in the bin directory with the matlab and mex executables). If you run mex -setup it will interactively create a copy for you, under ~/.matlab/RELEASE, for example:
or similar, and you may then further edit that copy if required. If you match the release, mex will find your copy of mexopts.sh.
mex: command not found error
If you get the error “mex: command not found” check that mex is in your path. Either add the MATLAB binary directory (usually /usr/local/matlab/bin) to your path or create a link to mex somewhere already in the path (usually /usr/local/bin).
Adding the path:
Creating a Link:
Another solution is to provide the full path to the mex executable in an environment variable called MEXBIN. It will be used by the Makefile instead of the default one.
This is pdfTeX, Version ... (TeX Live 2011) error
If you get the error:
mex: unrecognized option `-O'
mex: unrecognized option `-c'
This is pdfTeX, Version ... (TeX Live 2011)
This is due to a conflict between MATLAB mex and a LaTeX command (from the texlive package) with the same name. Change PATH or MEXBIN as described in the previous solution to make sure that the MATLAB mex executable is called first.
Missing files
If you get build errors such as “math.h does not exist” when trying to execute the command make && make install, then you probably need to install the build-essentials package.
At the command line in a Terminal, type:
or similar command to install a C/C++ compilation environment if you are not using a Debian-based Linux distribution.