Saturday, June 3, 2017

Building lightgbm in Mac Sierra

In order to build lightgbm in OSX Sierra, you might have to follow the steps provided by MS github
--
LightGBM depends on OpenMP for compiling, which isn't supported by Apple Clang.
Please use gcc/g++ instead.
Run following:
brew install cmake
brew install gcc --without-multilib
git clone --recursive https://github.com/Microsoft/LightGBM ; cd LightGBM
mkdir build ; cd build
cmake ..  ## cause errors
make -j 
ERRORs:  you might have errors as below caused by cmake.

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:8 (PROJECT):
  The CMAKE_C_COMPILER:

    gcc-7

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:8 (PROJECT):
  The CMAKE_CXX_COMPILER:

    g++-7

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also "/Users/xiezhen/Downloads/LightGBM/build/CMakeFiles/CMakeOutput.log".
See also "/Users/xiezhen/Downloads/LightGBM/build/CMakeFiles/CMakeError.log".



Solution:
Add the following code to after the second line of CMakeLists.txt in the folder of LightGBM. 

SET(MACOSX_DEPLOYMENT_TARGET ${DARWIN_MAJOR_SDK_VERSION}.${DARWIN_MINOR_SDK_VERSION})
SET(CMAKE_CXX_FLAGS "--sysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS}")

MESSAGE("Setting MACOSX_DEPLOYMENT_TARGET to '${MACOSX_DEPLOYMENT_TARGET}'.")