Skip to content

Building libcmaes on Mac OSX

Emmanuel Benazera edited this page Feb 2, 2015 · 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
git checkout dev
cd libcmaes
./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