wiki:Ipopt_on_Mac_OS_X

Ipopt and the Matlab Interface on Mac OS X

by Ray Zimmerman, Nov 27, 2012 (last updated May 2, 2013)

Build Notes

(See an older version of this page for details on building Ipopt on Snow Leopard 10.6 or Lion 10.7, or with other linear solvers or BLAS/LAPACK options.)

Here is an updated summary of my experience building Ipopt 3.10.3 and the Matlab interface for it on Mac OS X 10.8 Mountain Lion using the MUMPS linear solver and the native OS X BLAS/LAPACK[*1]. I've built both a 32-bit and 64-bit versions.

32-bit build (with Matlab R2010a)
64-bit build (with Matlab R2012b)

[*1] Note on native OS X BLAS -- Mac OS X includes it's own optimized BLAS and LAPACK libraries in the vecLib framework, which is a sub-component of the Accelerate framework. Using -framework Accelerate or -framework vecLib has the same effect and can be used interchangeably in this context. There was an issue using Ipopt with the Accelerate/vecLib framework in Lion that caused Ipopt to frequently fail. This issue has been fixed in Ipopt 3.10.3.

The Steps

1. Install wget.

I used wget-1.12 from http://www.merenbach.com/software/wget .

2. Install gfortran.

I used the gfortran from http://r.research.att.com/tools/ .

gfortran-lion-5666-3.pkg
http://r.research.att.com/gfortran-lion-5666-3.pkg

If you prefer to use a homebrew version of gfortran, you might want to check out these instructions, which have a few very minor changes from mine.

3. Download Ipopt and set up build environment.

I use ~/build as my build directory.

cd ~/build
tar zxvf ~/Downloads/Ipopt-3.10.3.tgz
cd ~/build/Ipopt-3.10.3/ThirdParty/Metis/
./get.Metis
cd ~/build/Ipopt-3.10.3/ThirdParty/Mumps/
./get.Mumps
cd ~/build/Ipopt-3.10.3
mkdir build64
mkdir build32

4. Configure Ipopt build.

The configure command depends on whether it is a 64-bit or 32-bit build:

64-bit

cd ~/build/Ipopt-3.10.3/build64
../configure --disable-shared \
  F77=gfortran FFLAGS="-fexceptions -m64 -fbackslash" \
  CFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch x86_64 -m64" \
  CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch x86_64 -m64"

32-bit

cd ~/build/Ipopt-3.10.3/build32
../configure --disable-shared \
  F77=gfortran FFLAGS="-fexceptions -m32 -fbackslash" \
  CFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch i386 -m32" \
  CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch i386 -m32"

5. Build, test and install Ipopt.

make
make test
make install

6. Set up Matlab MEX environment.

Create mexopts.sh file. This assumes you have your Matlab installed in /Applications.

64-bit

/Applications/MATLAB_R2012b.app/bin/mex -setup

(select option 1)

This creates a mexopts.sh file in the ~/.matlab/R2012b directory.
Make the modifications below in the maci64 section of this file.

32-bit

/Applications/MATLAB_R2010a.app/bin/mex -setup

(select option 1 or 2)

This creates a mexopts.sh file in the ~/.matlab/R2010a directory.
Make the modifications below in the maci section of this file.

Make these changes in the appropriate section of the mexopts.sh file:

  • change both instances of libgfortran.dylib to libgfortran.a in FC_LIBDIR line
    (my gfortran includes only static libs, besides I want this to work on machines without gfortran installed)
  • remove -Wl,-syslibroot,$SDKROOT from LDFLAGS line
    (otherwise it can't find gfortran libraries)
  • add the following line, below the existing LDFLAGS line(s):
    LDFLAGS="$LDFLAGS -framework vecLib"
    
  • It may also be necessary for some to change the FC line to include the full path for the gfortran compiler.

7. Build MEX file

Go to the MEX build directory, make the indicated modifications to the Makefile, then run make.

64-bit

cd ~/build/Ipopt-3.10.3/build64/Ipopt/contrib/MatlabInterface/src
  • change:
    MATLAB_HOME = /Applications/MATLAB_R2012b.app
    MEXSUFFIX   = mexmaci64
    
  • delete, from the LIBS line:
    • all duplicates
    • -L/usr/lib/gcc/i686-apple-darwin11/4.2.1/../../..
      (this causes it to find the wrong libmx.dylib, the one in /usr/lib rather than the Matlab one)
    • all instances of -framework vecLib
      (this is added in mexopts.sh now)
  • save Makefile, run make, then copy the MEX file to somewhere in your Matlab path, e.g.
    make
    cp ipopt.mexmaci64 ~/Documents/MATLAB
    

32-bit

cd ~/build/Ipopt-3.10.3/build32/Ipopt/contrib/MatlabInterface/src
  • change:
    MATLAB_HOME = /Applications/MATLAB_R2010a.app
    MEXSUFFIX   = mexmaci
    
  • delete, from the LIBS line:
    • all duplicates
    • -L/usr/lib/gcc/i686-apple-darwin11/4.2.1/../../..
      (this causes it to find the wrong libmx.dylib, the one in /usr/lib rather than the Matlab one)
    • all instances of -framework vecLib
      (this is added in mexopts.sh now)
  • add -maci to beginning of MEXFLAGS line
  • save Makefile, run make, then copy the MEX file to somewhere in your Matlab path, e.g.
    make
    cp ipopt.mexmaci ~/Documents/MATLAB
    

It may also be necessary for some to add something like -L/usr/local/gfortran/lib to the LIBS line.

Last modified 5 years ago Last modified on May 2, 2013 10:05:48 AM