Thomas Eckert

< writing /


Installing XGBoost on MacOS Without Crying

17 Feb 2018 | Seattle, WA

XGBoost can be used in machine learning to build faster models. The official documentation for installation is here. However, many users have hit a snag in the process on MacOS. This problem seems to stem from the implementation of Clang shipped with the operating system.

Clang is the compiler front-end for C-based languages. The default Clang on MacOS does not include support for OpenMP, an option that is required for compiling XGBoost. Without correcting for this, the following error will occur when compiling

clangclang: : errorclang: error: unsupported option '-fopenmp'
clang: error: unsupported option '-fopenmp'error
: unsupported option '-fopenmp': unsupported option '-fopenmp'

It may not be immediately clear what to do from this prompt. What it lacks in clarity, it makes up for in verbosity. In MacOS High Sierra, the included Clang is 4.0 with the OpenMP disabled on the built-in compiler.

When I encountered this problem, I did some Googling and found a common solution was to use Homebrew to download gcc without multilib support. But as can be seen here that option was removed from Homebrew.

For anyone who encounters this same problem in the future, I want to share how I was able to get a working installation:

  1. Change to the directory you want to put the XGBoost repo in.
  2. Clone the GitHub repository:
    git clone --recursive
  3. Use Homebrew to install gcc.
    brew install gcc
    This version will have the OpenMP option included.
  4. Install Apple's X-Code Command Line Tools
    xcode-select --install
    This will give us the g++-7 that we'll use for compiling.
  5. Change into the XGBoost directory and edit the file using vi.
    cd xgboost; cp make/ ./; vi
  6. Uncomment and edit lines 21 and 22 so that they say
    export CC = /usr/local/Cellar/gcc
    export CXX = /usr/local/bin/g++-7
    This will force the compiler to use the gcc and g++-7 that we just installed, rather than the MacOS default.
  7. Clean any digital detritus from previous install attempts
    make clean_all
  8. Compile using
    make -j4

I hope that works for you. Things may change down the road, as with the --without-multilib support being removed from Homebrew. This at least worked for me at the beginning of 2018.