Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Guide to Compilation on OSX

Dario Izzo edited this page May 11, 2015 · 1 revision

Compiling under OS X

As for a unix based operating system, under Mac OS X you will need to compile PaGMO from the source code. The following is described by using Homebrew available at http://brew.sh. We will assume that you have downloaded the git repository and that the working directory is pagmo/

We first suppose that you have a working Python installation. We recommend you to follow the tutorial http://hackercodex.com/guide/python-development-environment-on-mac-osx/ to install Python within a virtual environment to have a full control on your Python installation.

If you are not following the next installation description with Homebrew, then note that you need to compile boost thread and boost serialization. For PyGMO you will need a working python installation and the boost python library. For the GTOP database you will need boost date time.

  1. Install your favorite mpi library. For the purpose of this we will use OpenMPI. If you prefer, instead, you can install mpich2. Just type:

     brew install openmpi
    
  2. Install the boost libraries system wide (including boost thread and boost serialization) by typing:

     brew install boost --with-mpi
    
  3. Install the gsl libraries (optional):

     brew install gsl
    
  4. Compile and install nlopt library (optional):

     brew install nlopt
    
  5. Create a directory named build within the working directory and move there:

     mkdir build
     cd build
    
  6. Run ccmake to configure PaGMO. If you don't have ccmake already installed, download the binary available at http://www.cmake.org/cmake/resources/software.html). Assuming a system wide installation of the application we type

     ccmake ../
    
  7. Select the options you want. Choose to build main.cpp and/or PyGMO (the python module). Be careful to link to the correct python binaries/headers in case you are using the Homebrew Python. Double check that the libraries are well linked to the installed python and not the system python (/usr/lib/libpython2.7.dylib usually point to /System/Library/Frameworks/Python.framework/Versions/2.7/Python). In example, you should have the following includes (with a modified install prefix to the install PyGMO within the selected virtualenv, and the libraries versions corresponding to your system):

     CMAKE_INSTALL_PREFIX             /Users/<user name>/Virtualenvs/default
     Boost_INCLUDE_DIR                /usr/local/Cellar/boost/1.55.0/include
     GSL_INCLUDE_DIR                  /usr/local/Cellar/gsl/1.16/include
     MPI_CXX_INCLUDE_PATH             /usr/local/Cellar/open-mpi/1.7.3/include
     PYTHON_INCLUDE_DIR               /Users/<user name>/Virtualenvs/default/include/python2.7
     PYTHON_LIBRARY                   /Users/<user name>/Virtualenvs/default/lib/python2.7/config/libpython2.7.dylib
     NLOPT_INCLUDE_DIR                /usr/local/Cellar/nlopt/2.4.1/include
    

Configure two times and generate. Then quit.

  1. Now build the code

     make
    
  2. Install the libraries and python module by typing

     make install
    

What can go wrong?

Typical problems are:

  1. Under windows the code has been compiled several times using minGW and MSVC. Each time is a pain.
  2. In osx, the python installation is somehow different from linux machines and the correct detection of the site-packages directory can fail and may need to be manually set.
  3. In osx, the use of homebrew is suggested. Be careful to link to the correct python binaries/headers in case you are using the homebrew python (CMake does not detect them)
  4. Libraries autodected are messed up ... check carefully your cmake output
  5. On some systems (e.g Ubuntu) you may experience an large wall of errors reporting an undefined reference to boost::archive(...). This is due to the custom version of gcc that Ubuntu (and possibly other distros) ship with. Quick workaround is swapping the linking order of the pagmo_static and all the other libraries when building. This is done by modifying the the https://github.com/esa/pagmo/blob/master/CMakeLists.txt file. The line TARGET_LINK_LIBRARIES(main ${MANDATORY_LIBRARIES} pagmo_static) needs to be changed to TARGET_LINK_LIBRARIES(main pagmo_static ${MANDATORY_LIBRARIES}). Other solution is compiling gcc from sources and pointing to it with CMAKE_CXX_COMPILER and CMAKE_C_COMPILER in ccmake.
Clone this wiki locally