< writing /
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:
git clone --recursive https://github.com/dmlc/xgboost
This version will have the OpenMP option included.
brew install gcc
This will give us the g++-7 that we'll use for compiling.
config.mkfile using vi.
cd xgboost; cp make/config.mk ./config.mk; vi config.mk
This will force the compiler to use the gcc and g++-7 that we just installed, rather than the MacOS default.
export CC = /usr/local/Cellar/gcc export CXX = /usr/local/bin/g++-7
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.