Skip to content

Building libcmaes on Mac OSX

oliverks edited this page Jun 19, 2019 · 21 revisions

Building libcmaes

Instructions for compiling on OSX Maverick (10.9) [untested on other versions] with Mac Ports. Similar instructions should work for Homebrew users as well.

Quickstart (recommended)

with macports

  • install macports
  • install required packages
sudo port install autoconf
sudo port install automake
sudo port install eigen3
sudo port install gflags

with homebrew

sudo brew install autoconf
sudo brew install automake
sudo brew install libtool
sudo brew install eigen
sudo brew install gflags

(hint: a user reports gflags is better installed by hand)

building the lib

  • build libcmaes
git clone https://github.com/beniz/libcmaes.git
cd libcmaes
git checkout dev
./autogen.sh
./configure --with-eigen3-include=/opt/local/include/eigen3 CXXFLAGS="-I/opt/local/include -O3" LDADD=-lgflags LDFLAGS=-L/opt/local/lib
make
  • test libcmaes
./tests/test_functions

should return results of a run on fsphere in 2-D.

To use the Python bindings

with macports:

  • install the additional packages:
sudo port install boost +gcc48
sudo port install py-numpy

with homebrew:

sudo brew install boost --with-python
sudo brew install numpy

build python bindings

  • configure and compile:
./configure --with-eigen3-include=/opt/local/include/eigen3 CXXFLAGS="-I/opt/local/include -O3 -I/opt/local//Library/Frameworks/Python.framework/Versions/2.7/include -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include" LDADD=-lgflags LDFLAGS="-L/opt/local/lib" BOOST_LDFLAGS=-L/opt/local/lib --enable-python PYTHON=/opt/local/bin/python PYTHON_EXTRA_LDFLAGS="-u _PyMac_Error"  LDFLAGS="-L/opt/local/lib `python-config --ldflags` `python-config --libs`"
make
  • run:
cd python
export DYLD_LIBRARY_PATH=../src/.libs
/opt/local/bin/python ptest_bounds.py

Building with gcc (more complicated)

  • install macports and export PATH:
export PATH=$PATH:/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/local/git/bin
  • install gcc-47 or higher (gcc-48, gcc-49) from macports
sudo port install gcc48
sudo port install autoconf
sudo port install automake
  • install eigen3 from macports
sudo port install eigen3
  • install gflags from macports:
sudo port install gflags +gcc48
  • get libcmaes from github:
git clone https://github.com/beniz/libcmaes.git
  • configure libcmaes:
./autogen.sh
./configure CC=/opt/local/bin/gcc CXX=/opt/local/bin/g++ --with-eigen3-include=/opt/local/include/eigen3 CXXFLAGS="-lstdc++ -I/opt/local/include -O4" LDADD=-lgflags LDFLAGS=-L/opt/local/lib
  • build libcmaes
make
  • test libcmaes
./tests/test_functions

should return results of a run on fsphere in 2-D.

Building the library with Python bindings

The bindings have dependencies on:

  • boost-python
  • numpy Install both as needed:
sudo port install boost +gcc48
sudo port install py-numpy

Configure and build:

./autogen.sh
./configure CC=/opt/local/bin/gcc CXX=/opt/local/bin/g++ --with-eigen3-include=/opt/local/include/eigen3 CXXFLAGS="-lstdc++ -I/opt/local/include -O4 -I/opt/local/include/ -I/opt/local//Library/Frameworks/Python.framework/Versions/2.7/include -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include" LDADD=-lgflags LDFLAGS="-L/opt/local/lib" BOOST_LDFLAGS=-L/opt/local/lib --enable-python PYTHON=/opt/local/bin/python PYTHON_EXTRA_LDFLAGS="-u _PyMac_Error"  LDFLAGS="-L/opt/local/lib `python-config --ldflags` `python-config --libs`"
make

Test your bindings:

cd python
export DYLD_LIBRARY_PATH=../src/.libs
/opt/local/bin/python ptest_bounds.py

Building with Anaconda Python

Assuming that anaconda is installed in

/Users/you/anaconda

the following steps should allow you to compile libcmaes with python bindings for anaconda:

  • fix anaconda lib:
install_name_tool -id /Users/you/anaconda/lib/libpython2.7.dylib /Users/you/anaconda/lib/libpython2.7.dylib
  • (re-)compile boost python
mkdir /Users/you/tmp
cd /Users/you/tmp
wget http://sourceforge.net/projects/boost/files/boost/1.57.0/boost_1_57_0.tar.bz2/download
mv download boost_1_57_0.tar.bz2
tar xvjf boost_1_57_0.tar.bz2
mkdir /Users/you/anaconda_boost_install
cd boost_1_57_0
# export PATH=/usr/bin:/bin:/usr/sbin:/sbin:  # might be necessary to prevent custom compilers be used
./bootstrap.sh --prefix=/Users/you/anaconda_boost_install/ --with-python=/Users/you/anaconda/bin/python2.7
./b2 link=shared
./b2 link=shared install
# source ~/.bashrc  # get back $PATH
  • fix libboost-python against anaconda:
install_name_tool -id /Users/you/anaconda_boost_install/lib/libboost_python.dylib /Users/you/anaconda_boost_install/lib/libboost_python.dylib
  • finally build libcmaes with python bindings for anaconda
export PATH=/Users/you/anaconda/bin:$PATH
cd /path/to/libcmaes

If using 'brew':

./configure --enable-python CXXFLAGS="-O2 -I/Users/you/anaconda/lib/python2.7/site-packages/numpy/core/include/ -I/Users/you/anaconda_boost_install/include" LDFLAGS="-L/Users/you/anaconda_boost_install/lib"

else if using 'port':

./configure --enable-python --with-eigen3-include=/opt/local/include/eigen3 CXXFLAGS="-O2 -I/Users/you/anaconda/lib/python2.7/site-packages/numpy/core/include/ -I/Users/you/anaconda_boost_install/include" LDFLAGS="-L/Users/you/anaconda_boost_install/lib"

then:

make
cd python
export DYLD_LIBRARY_PATH=../src/.libs
/Users/you/anaconda/bin/python ptest.py

TIP: if you have already compiled libcmaes, after the call to configure, do cd python, then make clean && make. This would recompile only the python bindings part, which is enough.