suiji / Arborist

Scalable decision tree training and inference.
Other
82 stars 14 forks source link

R compilation fails under CentOS 7 #53

Closed Javdat closed 4 years ago

Javdat commented 4 years ago

I am trying to install Rborist as part of dependency for another package (VSURF) in R.

But compilation keeps failing inside the docker running CentOS 7.

Initial error was:

Error in model fit: C++14 standard requested but CXX14 is not defined 

So, I followed a suggestion to declare it in Makevars:

&& echo "CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function  -Wno-macro-redefined" >> ~/.R/Makevars \
&& echo "CXX14=g++ -std=c++1y -fPIC" >> ~/.R/Makevars \

But it is still falling:

* installing *source* package 'Rborist' ...
** package 'Rborist' successfully unpacked and MD5 sums checked
** libs
g++ -std=c++1y -fPIC  -I/opt/microsoft/ropen/3.5.3/lib64/R/include -DNDEBUG  -I"/opt/microsoft/ropen/3.5.3/lib64/R/library/Rcpp/include" -DU_STATIC_IMPLEMENTATION  -fopenmp   -O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function  -Wno-macro-redefined -c bagBridge.cc -o bagBridge.o
bagBridge.cc: In constructor 'BagBridge::BagBridge(unsigned int, unsigned int, const RawVector&)':
bagBridge.cc:43:28: error: 'make_unique' was not declared in this scope
   bmRaw(raw.length() > 0 ? make_unique<BitMatrix>((unsigned int*) &raw[0], nTree, nRow) : make_unique<BitMatrix>(0, 0)) {
                            ^
bagBridge.cc:43:49: error: expected primary-expression before '>' token
   bmRaw(raw.length() > 0 ? make_unique<BitMatrix>((unsigned int*) &raw[0], nTree, nRow) : make_unique<BitMatrix>(0, 0)) {
                                                 ^
bagBridge.cc:43:112: error: expected primary-expression before '>' token
   bmRaw(raw.length() > 0 ? make_unique<BitMatrix>((unsigned int*) &raw[0], nTree, nRow) : make_unique<BitMatrix>(0, 0)) {
                                                                                                                ^
bagBridge.cc: In static member function 'static std::unique_ptr<BagBridge> BagBridge::unwrap(const List&, const List&, bool)':
bagBridge.cc:81:10: error: 'make_unique' was not declared in this scope
   return make_unique<BagBridge>(as<unsigned int>(sBag["nRow"]),
          ^
bagBridge.cc:81:31: error: expected primary-expression before '>' token
   return make_unique<BagBridge>(as<unsigned int>(sBag["nRow"]),
                               ^
bagBridge.cc: In static member function 'static std::unique_ptr<BagBridge> BagBridge::unwrap(const List&)':
bagBridge.cc:100:10: error: 'make_unique' was not declared in this scope
   return make_unique<BagBridge>(as<unsigned int>(sBag["nRow"]),
          ^
bagBridge.cc:100:31: error: expected primary-expression before '>' token
   return make_unique<BagBridge>(as<unsigned int>(sBag["nRow"]),
                               ^
At global scope:
cc1plus: warning: unrecognized command line option "-Wno-macro-redefined" [enabled by default]
make: *** [bagBridge.o] Error 1
ERROR: compilation failed for package 'Rborist'
* removing '/opt/microsoft/ropen/3.5.3/lib64/R/library/Rborist'

OS: CentOS 7 R version: Microsoft R Open 3.5.3 (its based R-3.5.3)

Maybe someone has suggestions? Thank you!

suiji commented 4 years ago

The undeclared reference to make_unique() confirms that the compiler is not recognizing C++14.

Do you know what compiler you are using? The incantation for specifying C++14 can vary among compilers.

Javdat commented 4 years ago

Compiler was g++ at /usr/bin/g++

So, I decided to directly declare it:

CXX14=/usr/bin/g++

This did not work.

Apparently, the problem was that g++ was an old version (?):

g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)

So, I followed this: https://stackoverflow.com/questions/53552166/rstan-c14-error-while-installing-centos

Install g++8

yum install centos-release-scl
yum install devtoolset-8-gcc*

Enable it as default (believe this can be skipped if we are defining it in Makevars?)

scl enable devtoolset-8 bash

Locate it:

>which g++
/opt/rh/devtoolset-8/root/usr/bin/g++
>g++ --version
g++ (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)

Declare it in ~/.R/Makevars

CXX14FLAGS=-O3 -march=native -mtune=native -fPIC
CXX14=/opt/rh/devtoolset-8/root/usr/bin/g++

This fixed the problem.

Thank you.