Description
On Linux and Mac systems, the Fortran integrators included in PottersWheel
should be compiled to match the system's C++ and Fortran libraries.
Unfortunately, Matlab supports only rather old compiler versions, e.g.
gcc and gfortran version 4.3 on Matlab R2011b, while the default compiler
e.g. on Ubuntu 11.10 is of version 4.6. Therefore some combinations of Matlab
and Linux distributions are not compatible by default and may require manual
installation of gcc and gfortran, which is not always straight forward.
Supported compilers are listed on:
http://www.mathworks.com/support/compilers/current_release/
http://www.mathworks.com/support/compilers/previous_releases.html
Four steps are usually required to setup mex compilation in Matlab.
They are explained below in more detail.
1. Installation of a compatible gcc and gfortran compiler including the
developer libraries (and not only the *.so dynamic libraries)
2. Executing "mex -setup" in the Matlab command window to create the file
mexopts.sh e.g. in /home/<username>/.matlab/<release>/mexopts.sh
3. Adapting the mexopts.sh file by e.g. changing gcc to gcc-4.3
4. Test the mex compilation
Unsupported combinations of Matlab and Linux
The mex compilation is a prerequisite to run PottersWheel and won't
work on the following systems without special administration knowledge:
- Ubuntu 11.10 with any Matlab Release (as of 2011-10-23).
Please let us know if you identified further failed combinations.
Step 1: Installation of gcc 4.3
This description assumes installation of Ubuntu Linux.
Please let us know the corresponding commands on other Linux distributions.
Please check whether gcc-4.3 is already installed by typing
"gcc" in a Linux terminal and pressing the tabulator key twice to
see a list of matched commands, e.g.
maiwald@ubuntu-11.04:~$ gcc
gcc gcc-4.5
To find out the version of a compiler type e.g. "gcc -v".
Continue with step 2 if gcc-4.3 is already installed.
a) On Ubuntu 10.10 and below, the following bash commands should install
the GNU Compiler Collection 4.3 and the GNU Standard C++ Library
(compare https://help.ubuntu.com/community/MATLAB and
http://joysofprogramming.com/install-gfortran-4-3-ubuntu):
$ sudo apt-get install gcc-4.3-multilib libstdc++6-4.3-dev
$ sudo apt-get install gfortran-4.3
Finished.
b) On Ubuntu 11.04 download the corresponding *.deb files of Ubuntu Maverick
from (compare http://ubuntuforums.org/showthread.php?t=1748408):
http://packages.ubuntu.com/maverick/gcc-4.3-multilib
http://packages.ubuntu.com/maverick/g++-4.3-multilib
http://packages.ubuntu.com/maverick/gfortran-4.3
Recursively follow all "=" dependent packages resulting in 8 deb files:
i386:
gcc-4.3-multilib_4.3.5-3ubuntu1_i386.deb
gcc-4.3_4.3.5-3ubuntu1_i386.deb
gcc-4.3-base_4.3.5-3ubuntu1_i386.deb
g++-4.3_4.3.5-3ubuntu1_i386.deb
g++-4.3-multilib_4.3.5-3ubuntu1_i386.deb
cpp-4.3_4.3.5-3ubuntu1_i386.deb
gfortran-4.3_4.3.5-3ubuntu1_i386
libstdc++6-4.3-dev_4.3.5-3ubuntu1_i386.deb
amd64:
cpp-4.3_4.3.5-3ubuntu1_amd64.deb
g++-4.3_4.3.5-3ubuntu1_amd64.deb
g++-4.3-multilib_4.3.5-3ubuntu1_amd64.deb
gcc-4.3_4.3.5-3ubuntu1_amd64.deb
gcc-4.3-base_4.3.5-3ubuntu1_amd64.deb
gcc-4.3-multilib_4.3.5-3ubuntu1_amd64.deb
gfortran-4.3_4.3.5-3ubuntu1_amd64.deb
libstdc++6-4.3-dev_4.3.5-3ubuntu1_amd64.deb
Change the current bash working directory to the folder with the
downloaded *.deb file and execute
$ sudo dpkg -i *.deb
Then a few broken links have to be corrected (shown only for amd64):
Broken links:
/usr/lib/gcc/x86_64-linux-gnu/4.3/libgcc_s.so -> /lib/libgcc_s.so.1
/usr/lib/gcc/x86_64-linux-gnu/4.3/libgomp.so -> ../../../libgomp.so.1
/usr/lib/gcc/x86_64-linux-gnu/4.3/libstdc++.so -> ../../../libstdc++.so.6
/usr/lib/gcc/x86_64-linux-gnu/4.3/libgfortran.so -> ../../../libgfortran.so.3
Correction (each command is one line, the 'f' option is to force
overwritting the existing links):
sudo ln -sf /lib/x86_64-linux-gnu/libgcc_s.so.1 \
/usr/lib/gcc/x86_64-linux-gnu/4.3/libgcc_s.so
sudo ln -sf /usr/lib/x86_64-linux-gnu/libgomp.so.1 \
/usr/lib/gcc/x86_64-linux-gnu/4.3/libgomp.so
sudo ln -sf /usr/lib/x86_64-linux-gnu/libstdc++.so.6 \
/usr/lib/gcc/x86_64-linux-gnu/4.3/libstdc++.so
sudo ln -sf /usr/lib/x86_64-linux-gnu/libgfortran.so.3 \
/usr/lib/gcc/x86_64-linux-gnu/4.3/libgfortran.so
Finished.
c) On Ubuntu 11.10 both approaches will not work but lead to the following
error message (compare http://ubuntuforums.org/showthread.php?p=11378416):
dpkg: dependency problems prevent configuration of gcc-4.3:
libgcc1:i386 (1:4.6.1-9ubuntu3) breaks gcc-4.3 and is installed.
libgcc1 (1:4.6.1-9ubuntu3) breaks gcc-4.3 and is installed.
Please let us know if you have a working solution for this case.
d) Other Linux systems will be desrcribed in the future.
Please let use know how you got your system working.
Step 2: Creating a user specific mex options file
Please check whether the file mexopts.sh is already available in
/home/<username>/.matlab/<Release>/mexopts.sh
If not it has to be created. Open Matlab and type "mex -setup".
Then select "Template Options file for building gcc MEX-files".
Example:
mex -setup
Options files control which compiler to use, the compiler and link command
options, and the runtime libraries to link against.
Using the 'mex -setup' command selects an options file that is
placed in /home/thomas/.matlab/R2011b and used by default for 'mex'. An options
file in the current working directory or specified on the command line
overrides the default options file in /home/thomas/.matlab/R2011b.
To override the default options file, use the 'mex -f' command
(see 'mex -help' for more information).
The options files available for mex are:
1: /home/thomas/programs/matlab/bin/mexopts.sh :
Template Options file for building gcc MEX-files
0: Exit with no changes
Enter the number of the compiler (0-1):
1
/home/maiwald/programs/matlab/bin/mexopts.sh is being copied to
/home/maiwald/.matlab/R2011b/mexopts.sh
Step 3: Adapt the mexopts.sh file
Determine the mex extension of your Matlab installation by executing
the Matlab command
mexext
The result could be e.g. mexa64.
Open the file /home/<username>/.matlab/<release>/mexopts.sh in a
text editor of your choice, e.g. the matlab editor:
edit /home/<username>/.matlab/<release>/mexopts.sh
Find the section corresponding to your mex extension, i.e. where the
value of LDEXTENSION matches your mex extension.
Make the following changes:
CC='gcc-4.3'
CXX='g++-4.3'
FC='gfortran-4.3'
Save the file and test the mex compilation.
The current settings can be listes using
mex -v
Step 4: Test the mex compilation
Compile the test file 'pwMexTest.c' available in the PottersWheel toolbox
folder. If the test file is missing, just create it with the following content:
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mexPrintf("The mex compiler seems to work on your system. Good!\n");
}
Execute the following two commands:
pwGoToToolboxFolder;
mex pwMexTest.c
When you then run pwMexTest, the following message should appear:
pwMexTest
The mex compiler seems to work on your system. Good!
Now, the Fortran compiler will be tested:
pwGoToToolboxFolder;
mex radau5Mex.c options.c radau5.f dc_lapack.f lapack.f lapackc.f
Calling then radau5Mex should produce an error message complaining
about an invalid number of arguments. If this is the case, please run
pwCompileFortranIntegrators
Else, go to the troubleshooting section.
Troubleshooting
We list common error messages and our corresponding recommendations:
GLIBXX_3.4.14 not found
Warning: You are using gcc version "4.5.2-8ubuntu4)". The version
currently supported with MEX is "4.3.4".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
.../x86_64-linux-gnu/4.5.2/cc1: .../glnxa64/libstdc++.so.6:
version `GLIBCXX_3.4.14' not found (required by /usr/lib/libppl_c.so.2)
.../x86_64-linux-gnu/4.5.2/cc1: .../glnxa64/libstdc++.so.6:
version `GLIBCXX_3.4.11' not found (required by /usr/lib/libppl_c.so.2)
...
mex: compile of ' "pwMexTest.c"' failed.
Please install gcc-4.3 and/or correct the mexopts.sh
file as described above.
References
http://en.wikibooks.org/wiki/SPM/Installation_on_64bit_Linux
See also