LightGBM icon indicating copy to clipboard operation
LightGBM copied to clipboard

[R] [OSX] Installation error - Compilation error

Open coforfe opened this issue 9 years ago • 39 comments

Hello,

Thanks for your effort in porting this into R. I have just tried to install it in my Mac (just immediately after opening RStudio) using the command you recommend:

devtools::install_github("Microsoft/LightGBM", subdir = "R-package")

And I get this error:

> devtools::install_github("Microsoft/LightGBM", subdir = "R-package")
Downloading GitHub repo Microsoft/LightGBM@master
from URL https://api.github.com/repos/Microsoft/LightGBM/zipball/master
Installing lightgbm
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore  \
  --quiet CMD INSTALL  \
  '/private/var/folders/8n/k_qspzhn477d7stc4lbq0qrr0000gn/T/RtmpsybxTu/devtools99ca19667a32/Microsoft-LightGBM-cadcdf6/R-package'  \
  --library='/Library/Frameworks/R.framework/Versions/3.3/Resources/library' --install-tests 

* installing *source* package ‘lightgbm’ ...
** libs
clang++ -std=c++11 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I../..//include -DUSE_SOCKET -Wno-deprecated-declarations -I/usr/local/opt/llvm/include     -std=c++11 -fPIC  -Wall -mtune=core2 -g -O2 -c lightgbm-all.cpp -o lightgbm-all.o
In file included from lightgbm-all.cpp:2:
In file included from ./../../src/application/application.cpp:13:
./../../src/application/predictor.hpp:9:10: fatal error: 'omp.h' file not found
#include <omp.h>
         ^
1 error generated.
make: *** [lightgbm-all.o] Error 1
ERROR: compilation failed for package ‘lightgbm’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/lightgbm’
Error: Command failed (1)

This is the sessionInfo():

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.2

locale:
[1] es_ES.UTF-8/es_ES.UTF-8/es_ES.UTF-8/C/es_ES.UTF-8/es_ES.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] httr_1.2.1      R6_2.2.0        tools_3.3.2     withr_1.0.2     curl_2.3        memoise_1.0.0  
[7] git2r_0.18.0    digest_0.6.11   devtools_1.12.0

Please let me know if you need more details.

Thanks, Carlos.

coforfe avatar Jan 11 '17 23:01 coforfe

it is the openmp error in osx. You can find the quick solution at https://github.com/dmlc/xgboost/issues/276 . We will fix this soon as well.

@wxchan Did you have tried compiled by clang-omp/clang-omp++ ? Is its performance better than gcc in oxs ? refer to https://github.com/Microsoft/LightGBM/issues/89

guolinke avatar Jan 12 '17 01:01 guolinke

Hi there, I am trying to install this package from github as well. Yet, the issue also occurs to me while installing the package. I have seen the reference you tag above, but I could not solve it by myself. Is there any technical support or a simple guide to solve this problem? Thanks in advance for your help

BonnyRead avatar Jan 12 '17 02:01 BonnyRead

@BonnyRead what is your environment ? OSX / linux / windows ? What is the error message?

guolinke avatar Jan 12 '17 02:01 guolinke

I am sorry for forgetting post this crucial information.

My environment is Mac OS Sierra 10.12.1

This is my session info in R

R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.1
 

locale:
[1] zh_TW.UTF-8/zh_TW.UTF-8/zh_TW.UTF-8/C/zh_TW.UTF-8/zh_TW.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] httr_1.2.1      R6_2.2.0        tools_3.3.2     withr_1.0.2     curl_2.3       
[6] memoise_1.0.0   git2r_0.16.0    digest_0.6.10   devtools_1.12.0

This is the error message showed while installing

In file included from lightgbm-all.cpp:2:
In file included from ./../../src/application/application.cpp:13:
./../../src/application/predictor.hpp:9:10: fatal error: 'omp.h' file not found
#include <omp.h>
         ^
1 error generated.
make: *** [lightgbm-all.o] Error 1
ERROR: compilation failed for package ‘lightgbm’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/lightgbm’
Error: Command failed (1)

I have follow some steps in the aforementioned issues.

However, there is some step involved in xgboost rather than lightGBM. I am not a good engineer so I can't get some technical terms. i would be appreciate if there is a well-organized steps to deal with this issue.

BonnyRead avatar Jan 12 '17 02:01 BonnyRead

OK. A quick solution:

  1. install gcc:
brew install gcc --without-multilib
  1. edit and add following in ~/.R/Makevars
CC=gcc-6
CXX=g++-6
SHLIB_OPENMP_CFLAGS = -fopenmp
SHLIB_OPENMP_CXXFLAGS = -fopenmp
SHLIB_OPENMP_FCFLAGS = -fopenmp
SHLIB_OPENMP_FFLAGS = -fopenmp

guolinke avatar Jan 12 '17 02:01 guolinke

Thanks for your quick reply It takes me a long time to set gcc. Even though I installed it, it does arouse another error. It seems that it is about the edited file ~/.R/Makevars I use VIM to modify this file. Is it about the way to modify the file?

clang++ -std=c++11 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I../..//include -DUSE_SOCKET -Wno-deprecated-declarations -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include   -fopenmp  -std=c++11 -fPIC  -Wall -mtune=core2 -g -O2 -c lightgbm-all.cpp -o lightgbm-all.o
clang: error: unsupported option '-fopenmp'
make: *** [lightgbm-all.o] Error 1
ERROR: compilation failed for package ‘lightgbm’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/lightgbm’
Error: Command failed (1)

BonnyRead avatar Jan 12 '17 05:01 BonnyRead

@BonnyRead It is still compiled by clang++, not gcc...

guolinke avatar Jan 12 '17 05:01 guolinke

I see what's your point, but I could not find a way to switch the compiler of Xcode.

I am not familiar with this issue, R is the only language that I am able to use.

Is this project connected to C or C++.

Google only shows some discussions about how to switch compiler of a C++ project in Xcode

BonnyRead avatar Jan 12 '17 07:01 BonnyRead

compiling with clang-omp not succeeds for me.

wxchan avatar Jan 12 '17 07:01 wxchan

@BonnyRead you are using xcode? not command line to compile ? solution 1: install gcc for xcode: https://www.cyberciti.biz/faq/howto-apple-mac-os-x-install-gcc-compiler/ solution 2: use comand line to install R package. I don't have a osx to test.

@wxchan it seems need to change all <omp.h> to <libiomp/omp.h>

guolinke avatar Jan 12 '17 08:01 guolinke

I am being confused by the information came from internet.

Since i search on compiler gcc and the xcode shows.

Hence, I think it is all about Xcode. The truth is that I compile with command line.

All in all, I could not install from devtools::install_github, right?

The thing is I have not install package without Rstudio.

cd R-package
R CMD INSTALL --build  .

This code seems like doesn't work as I imagined.

-bash: cd: R-package: No such file or directory

I am new to Mac OS. In my opinion, do I need to create or set a folder for me to install the package?

I am really sorry for disturbing you.

BonnyRead avatar Jan 12 '17 09:01 BonnyRead

@BonnyRead , Tried to complied LightGBM through console will make it easier for installing.

R-pacage is under the source folder of LightGBM, please try to update the source code to the latest one by

git pull under the source folder of LightGBM

chivee avatar Jan 12 '17 09:01 chivee

@BonnyRead not, you don't need to create an new folder. I think you can still use install_github. BTW, can you paste the content of your ~/.R/Makevars ?

guolinke avatar Jan 12 '17 09:01 guolinke

@chivee I don't get what you mean. Had I better to install the package under the console of Rstudio? Also, what kind of source code should I update. I do not see what R-pacage folder under LightGBM.

@guolinke Here it is.

C=gcc-6
CXX=g++-6
SHLIB_OPENMP_CFLAGS = -fopenmp
SHLIB_OPENMP_CXXFLAGS = -fopenmp
SHLIB_OPENMP_FCFLAGS = -fopenmp
SHLIB_OPENMP_FFLAGS = -fopenmp

Actually, I copy entirely from your post. Something goes wrong?

BonnyRead avatar Jan 12 '17 09:01 BonnyRead

@BonnyRead It is very weird. Can you also try to install from local?

git clone --recursive https://github.com/Microsoft/LightGBM ; cd LightGBM
cd R-package
R CMD INSTALL --build  .

It still not success, paste your error message here.

guolinke avatar Jan 12 '17 10:01 guolinke

try add CXX1X=g++-6 to ~/.R/Makevars

but I still fail to install R-package, error like following:

** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  无法载入共享目标对象‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/lightgbm/libs/lightgbm.so’::
  dlopen(/Library/Frameworks/R.framework/Versions/3.3/Resources/library/lightgbm/libs/lightgbm.so, 6): Symbol not found: _GOMP_parallel
  Referenced from: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/lightgbm/libs/lightgbm.so
  Expected in: flat namespace
 in /Library/Frameworks/R.framework/Versions/3.3/Resources/library/lightgbm/libs/lightgbm.so
错误: 载入失败
停止执行
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/lightgbm’
错误: Command failed (1)

wxchan avatar Jan 12 '17 10:01 wxchan

@wxchan add -lgomp to PKG_LIBS in R-package/src/Makevars.

guolinke avatar Jan 12 '17 10:01 guolinke

Hello,

I got a little more progress in the compilation process but still with errors. This is what I did.

  • First I have reinstalled gcc with
brew reinstall gcc --without-multilib
  • I tried some different combinations in Makevars file. And this is the one that I finally used, that got a further progress:
CC=gcc-6
CXX=g++-6
LDFLAGS=-L/usr/local/opt/llvm/lib
CPPFLAGS=-I/usr/local/opt/llvm/include

And these are the error messages:

> devtools::install_github("Microsoft/LightGBM", subdir = "R-package")
Downloading GitHub repo Microsoft/LightGBM@master
from URL https://api.github.com/repos/Microsoft/LightGBM/zipball/master
Installing lightgbm
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore  \
  --quiet CMD INSTALL  \
  '/private/var/folders/8n/k_qspzhn477d7stc4lbq0qrr0000gn/T/RtmpsybxTu/devtools99ca31693583/Microsoft-LightGBM-300cee5/R-package'  \
  --library='/Library/Frameworks/R.framework/Versions/3.3/Resources/library' --install-tests 

* installing *source* package ‘lightgbm’ ...
** libs
clang++ -std=c++11 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I../..//include -DUSE_SOCKET -Wno-deprecated-declarations -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include   -fopenmp  -std=c++11 -fPIC  -Wall -mtune=core2 -g -O2 -c lightgbm-all.cpp -o lightgbm-all.o
clang: error: unsupported option '-fopenmp'
make: *** [lightgbm-all.o] Error 1
ERROR: compilation failed for package ‘lightgbm’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/lightgbm’
Error: Command failed (1)
> devtools::install_github("Microsoft/LightGBM", subdir = "R-package")
Downloading GitHub repo Microsoft/LightGBM@master
from URL https://api.github.com/repos/Microsoft/LightGBM/zipball/master
Installing lightgbm
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore  \
  --quiet CMD INSTALL  \
  '/private/var/folders/8n/k_qspzhn477d7stc4lbq0qrr0000gn/T/RtmpsybxTu/devtools99ca240d7b35/Microsoft-LightGBM-300cee5/R-package'  \
  --library='/Library/Frameworks/R.framework/Versions/3.3/Resources/library' --install-tests 

* installing *source* package ‘lightgbm’ ...
** libs
clang++ -std=c++11 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I../..//include -DUSE_SOCKET -Wno-deprecated-declarations -I/usr/local/opt/llvm/include     -std=c++11 -fPIC  -Wall -mtune=core2 -g -O2 -c lightgbm-all.cpp -o lightgbm-all.o
In file included from lightgbm-all.cpp:30:
In file included from ./../../src/treelearner/data_parallel_tree_learner.cpp:1:
./../../src/treelearner/parallel_tree_learner.h:25:16: warning: 'Init' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  virtual void Init(const Dataset* train_data);
               ^
./../../src/treelearner/serial_tree_learner.h:33:8: note: overridden virtual function is here
  void Init(const Dataset* train_data) override;
       ^
1 warning generated.
clang++ -std=c++11 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I../..//include -DUSE_SOCKET -Wno-deprecated-declarations -I/usr/local/opt/llvm/include     -std=c++11 -fPIC  -Wall -mtune=core2 -g -O2 -c lightgbm_R.cpp -o lightgbm_R.o
In file included from lightgbm_R.cpp:14:
././lightgbm_R.h:18:1: error: unknown type name 'DllExport'
DllExport SEXP LGBM_GetLastError_R(SEXP buf_len, SEXP actual_len, SEXP err_msg);
^
././lightgbm_R.h:18:15: error: expected ';' after top level declarator
DllExport SEXP LGBM_GetLastError_R(SEXP buf_len, SEXP actual_len, SEXP err_msg);
              ^
              ;
././lightgbm_R.h:30:1: error: unknown type name 'DllExport'
DllExport SEXP LGBM_DatasetCreateFromFile_R(SEXP filename,
^
././lightgbm_R.h:30:15: error: expected ';' after top level declarator
DllExport SEXP LGBM_DatasetCreateFromFile_R(SEXP filename,
              ^
              ;
././lightgbm_R.h:49:1: error: unknown type name 'DllExport'
DllExport SEXP LGBM_DatasetCreateFromCSC_R(SEXP indptr,
^
././lightgbm_R.h:49:15: error: expected ';' after top level declarator
DllExport SEXP LGBM_DatasetCreateFromCSC_R(SEXP indptr,
              ^
              ;
././lightgbm_R.h:71:1: error: unknown type name 'DllExport'
DllExport SEXP LGBM_DatasetCreateFromMat_R(SEXP data,
^
././lightgbm_R.h:71:15: error: expected ';' after top level declarator
DllExport SEXP LGBM_DatasetCreateFromMat_R(SEXP data,
              ^
              ;
././lightgbm_R.h:88:1: error: unknown type name 'DllExport'
DllExport SEXP LGBM_DatasetGetSubset_R(SEXP handle,
^
././lightgbm_R.h:88:15: error: expected ';' after top level declarator
DllExport SEXP LGBM_DatasetGetSubset_R(SEXP handle,
              ^
              ;
././lightgbm_R.h:101:1: error: unknown type name 'DllExport'
DllExport SEXP LGBM_DatasetSetFeatureNames_R(SEXP handle,
^
././lightgbm_R.h:101:15: error: expected ';' after top level declarator
DllExport SEXP LGBM_DatasetSetFeatureNames_R(SEXP handle,
              ^
              ;
././lightgbm_R.h:111:1: error: unknown type name 'DllExport'
DllExport SEXP LGBM_DatasetGetFeatureNames_R(SEXP handle,
^
././lightgbm_R.h:111:15: error: expected ';' after top level declarator
DllExport SEXP LGBM_DatasetGetFeatureNames_R(SEXP handle,
              ^
              ;
././lightgbm_R.h:123:1: error: unknown type name 'DllExport'
DllExport SEXP LGBM_DatasetSaveBinary_R(SEXP handle,
^
././lightgbm_R.h:123:15: error: expected ';' after top level declarator
DllExport SEXP LGBM_DatasetSaveBinary_R(SEXP handle,
              ^
              ;
././lightgbm_R.h:132:1: error: unknown type name 'DllExport'
DllExport SEXP LGBM_DatasetFree_R(SEXP handle,
^
././lightgbm_R.h:132:15: error: expected ';' after top level declarator
DllExport SEXP LGBM_DatasetFree_R(SEXP handle,
              ^
              ;
././lightgbm_R.h:145:1: error: unknown type name 'DllExport'
DllExport SEXP LGBM_DatasetSetField_R(SEXP handle,
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [lightgbm_R.o] Error 1
ERROR: compilation failed for package ‘lightgbm’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/lightgbm’
Error: Command failed (1)
> 

Thanks, Carlos.

coforfe avatar Jan 12 '17 20:01 coforfe

@guolinke I guess you ask me to paste your code on my terminal This is what i get after paste it into terminal and run

* installing to library ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library’
* installing *source* package ‘lightgbm’ ...
** libs
clang++ -std=c++11 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I../..//include -DUSE_SOCKET -Wno-deprecated-declarations -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include   -fopenmp  -std=c++11 -fPIC  -Wall -mtune=core2 -g -O2 -c lightgbm-all.cpp -o lightgbm-all.o
clang: error: unsupported option '-fopenmp'
make: *** [lightgbm-all.o] Error 1
ERROR: compilation failed for package ‘lightgbm’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/lightgbm’

It seems that I still use clang++ as my compiler.

However, I reenter the code for installing gcc again.

Warning: gcc-6.3.0_1 already installed

Seems like I have already done that before.

Is there any necessary procedure which need to be done in terminal to switch my compiler?

BonnyRead avatar Jan 13 '17 02:01 BonnyRead

@wxchan Did you install successfully now? can you share some experiences ?

guolinke avatar Jan 13 '17 02:01 guolinke