david-cortes / isotree

(Python, R, C/C++) Isolation Forest and variations such as SCiForest and EIF, with some additions (outlier detection + similarity + NA imputation)
https://isotree.readthedocs.io
BSD 2-Clause "Simplified" License
186 stars 38 forks source link

Difficulty installing Isotree for R on Linux #36

Closed jgarrigan closed 2 years ago

jgarrigan commented 2 years ago

I am trying to install isotree for R on Linux but I am getting the following error:

In file included from Rwrapper.cpp:75:0: isotree.h:224:12: error: ‘isinf’ is already declared in this scope using std::isinf; ^ isotree.h:225:12: error: ‘isnan’ is already declared in this scope using std::isnan; ^ make: *** [Rwrapper.o] Error 1 ERROR: compilation failed for package ‘isotree’

The downloaded source packages are in ‘/tmp/RtmpGs2W4l/downloaded_packages’

I'm out of my depth with error and don't know how to troubleshoot it. I'd be very grateful if you had any suggestions.

david-cortes commented 2 years ago

Thanks for the bug report. There seems to be an issue with your compiler headers and I'd be curious to know what kind of compiler are you using and whether you are trying to use this compiler with the headers from a different compiler or something like that. You can check R compilation configurations with the following command in a terminal:

R CMD config --all

(Please put three backticks (`) before and after the pasted output so that it becomes formatted)

I've nevertheless pushed a small update which might fix it - could you give it a try?

remotes::install_github("david-cortes/isotree")
jgarrigan commented 2 years ago

Hi David,

Thanks for the feedback, please see my system information below.


CC = gcc -std=gnu99
CFLAGS = -g -O2
CPICFLAGS = -fpic
CPPFLAGS = -I/usr/local/include
CXX = g++ -std=gnu++11
CXXFLAGS = -g -O2
CXXPICFLAGS = -fpic
CXX11 = g++
CXX11STD = -std=gnu++11
CXX11FLAGS = -g -O2
CXX11PICFLAGS = -fpic
CXX14 =
CXX14STD =
CXX14FLAGS =
CXX14PICFLAGS =
CXX17 =
CXX17STD =
CXX17FLAGS =
CXX17PICFLAGS =
CXX20 =
CXX20STD =
CXX20FLAGS =
CXX20PICFLAGS =
DYLIB_EXT = .so
DYLIB_LD = gcc -std=gnu99
DYLIB_LDFLAGS = -shared -fopenmp
FC = gfortran
FFLAGS = -g -O2
FPICFLAGS = -fpic
FLIBS = -lgfortran -lm -lquadmath
FCFLAGS = -g -O2
SAFE_FFLAGS = -g -O2 -msse2 -mfpmath=sse
OBJC = gcc
OBJCFLAGS = -g -O2 -fobjc-exceptions
JAVA = /opt/java/current/jre/bin/java
JAVAC = /opt/java/current/bin/javac
JAVAH = /opt/java/current/bin/javah
JAR = /opt/java/current/bin/jar
JAVA_HOME = /opt/java/current
JAVA_LIBS = -L/opt/java/current/jre/lib/amd64/server -ljvm
JAVA_CPPFLAGS = -I/opt/java/current/include -I/opt/java/current/include/linux
LDFLAGS = -L/usr/local/lib
SHLIB_CFLAGS =
SHLIB_CXXFLAGS =
SHLIB_CXXLD = g++ -std=gnu++11
SHLIB_CXXLDFLAGS = -shared
SHLIB_CXX11LD = g++ -std=gnu++11
SHLIB_CXX11LDFLAGS = -shared
SHLIB_CXX14LD =
SHLIB_CXX14LDFLAGS = -shared
SHLIB_CXX17LD =
SHLIB_CXX17LDFLAGS = -shared
SHLIB_CXX20LD =
SHLIB_CXX20LDFLAGS = -shared
SHLIB_EXT = .so
SHLIB_FFLAGS =
SHLIB_LD = gcc -std=gnu99
SHLIB_LDFLAGS = -shared
TCLTK_CPPFLAGS = -I/usr/include -I/usr/include
TCLTK_LIBS = -L/usr/lib64 -ltcl8.5 -L/usr/lib64 -ltk8.5 -lX11
BLAS_LIBS = -L/opt/R/4.0.5/lib/R/lib -lRblas
LAPACK_LIBS = -L/opt/R/4.0.5/lib/R/lib -lRlapack
MAKE = make
LIBnn = lib
AR = ar
NM = /usr/bin/nm -B
RANLIB = ranlib
LTO =
LTO_FC =
LTO_LD =
## The following variables are deprecated
CPP = gcc -std=gnu99 -E
CXXCPP = g++ -std=gnu++11 -E```
jgarrigan commented 2 years ago
remotes::install_github("david-cortes/isotree")

I tried the remotes install but got the following error which appears to be similar to the original issue I raised above


Downloading GitHub repo david-cortes/isotree@HEAD
'/usr/bin/git' clone --depth 1 --no-hardlinks --recurse-submodules https://github.com/Tessil/robin-map /tmp/RtmpY0r07e/remotes1f9440f95a8/david-cortes-isotree-d77387c/src/robinmap
Cloning into '/tmp/RtmpY0r07e/remotes1f9440f95a8/david-cortes-isotree-d77387c/src/robinmap'...
✓  checking for file ‘/tmp/RtmpY0r07e/remotes1f9440f95a8/david-cortes-isotree-d77387c/DESCRIPTION’ (587ms)
─  preparing ‘isotree’:
✓  checking DESCRIPTION meta-information ...
─  cleaning src
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
   Removed empty directory ‘isotree/docs’
   Removed empty directory ‘isotree/example’
   Removed empty directory ‘isotree/gen_tables’
   Removed empty directory ‘isotree/image’
   Removed empty directory ‘isotree/include’
   Removed empty directory ‘isotree/isotree’
   Removed empty directory ‘isotree/timings’
─  building ‘isotree_0.5.15.tar.gz’
   Warning: invalid uid value replaced by that for user 'nobody'

Installing package into ‘/home/myname/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
* installing *source* package ‘isotree’ ...
** using staged installation
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C++... yes
checking whether g++ accepts -g... yes
checking for g++ option to enable C++11 features... none needed
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -std=gnu++11 -I"/opt/R/4.0.5/lib/R/include" -DNDEBUG -D_FOR_R -D_USE_XOSHIRO -D_USE_ROBIN_MAP -DSUPPORTS_RESTRICT=1  -I'/opt/R/4.0.5/lib/R/library/Rcpp/include' -I/usr/local/include  -fopenmp -fno-math-errno -fno-trapping-math -fvisibility=hidden -fpic  -g -O2  -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++11 -I"/opt/R/4.0.5/lib/R/include" -DNDEBUG -D_FOR_R -D_USE_XOSHIRO -D_USE_ROBIN_MAP -DSUPPORTS_RESTRICT=1  -I'/opt/R/4.0.5/lib/R/library/Rcpp/include' -I/usr/local/include  -fopenmp -fno-math-errno -fno-trapping-math -fvisibility=hidden -fpic  -g -O2  -c Rwrapper.cpp -o Rwrapper.o
In file included from Rwrapper.cpp:75:0:
isotree.hpp:243:12: error: ‘isinf’ is already declared in this scope
 using std::isinf;
            ^
isotree.hpp:246:12: error: ‘isnan’ is already declared in this scope
 using std::isnan;
            ^
make: *** [Rwrapper.o] Error 1
ERROR: compilation failed for package ‘isotree’
* removing ‘/home/jgarrig1/R/x86_64-pc-linux-gnu-library/4.0/isotree’
Warning message:
In i.p(...) :
  installation of package ‘/tmp/RtmpY0r07e/file1f9d20a326/isotree_0.5.15.tar.gz’ had non-zero exit status```
david-cortes commented 2 years ago

Hmm, that's really weird, since many CRAN checks test a setup like that (GCC defaultting to g++11) and do not show any issue in CRAN servers.

Could you run these commands and paste the outputs here?

gcc --version
g++ --version

What distribution and version are you using?

jgarrigan commented 2 years ago

Hi David,

Please see the info below for system information and R version



[myname@rst-medica-myname-09a9-0 Medical-Outliers]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

> g++ --version
[myname@rst-medica-myname-09a9-0 Medical-Outliers]$ g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.```

```> R.Version()
$platform
[1] "x86_64-pc-linux-gnu"

$arch
[1] "x86_64"

$os
[1] "linux-gnu"

$system
[1] "x86_64, linux-gnu"

$status
[1] ""

$major
[1] "4"

$minor
[1] "0.5"

$year
[1] "2021"

$month
[1] "03"

$day
[1] "31"

$`svn rev`
[1] "80133"

$language
[1] "R"

$version.string
[1] "R version 4.0.5 (2021-03-31)"

$nickname
[1] "Shake and Throw"

Warning message:
In system("timedatectl", intern = TRUE) :
  running command 'timedatectl' had status 1```

```> sessionInfo()
R version 4.0.5 (2021-03-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblasp-r0.3.3.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] ggcorrplot_0.1.3  sparklyr_1.7.5    comorbidity_1.0.0 word2vec_0.3.4    scales_1.1.1      lubridate_1.8.0   ggrepel_0.9.1    
 [8] DBI_1.1.2         dbplyr_2.1.1      forcats_0.5.1     stringr_1.4.0     dplyr_1.0.8       purrr_0.3.4       readr_2.1.2      
[15] tidyr_1.2.0       tibble_3.1.6      ggplot2_3.3.5     tidyverse_1.3.1   pacman_0.5.1     

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.2  forge_0.2.0       haven_2.4.3       colorspace_2.0-3  vctrs_0.3.8       generics_0.1.2    htmltools_0.5.2  
 [8] base64enc_0.1-3   utf8_1.2.2        rlang_1.0.2       pillar_1.7.0      glue_1.6.2        withr_2.5.0       modelr_0.1.8     
[15] readxl_1.3.1      lifecycle_1.0.1   munsell_0.5.0     gtable_0.3.0      cellranger_1.1.0  rvest_1.0.2       htmlwidgets_1.5.4
[22] fastmap_1.1.0     tzdb_0.2.0        fansi_1.0.2       r2d3_0.2.6        broom_0.7.12      Rcpp_1.0.8.3      backports_1.4.1  
[29] jsonlite_1.8.0    fs_1.5.2          hms_1.1.1         digest_0.6.29     stringi_1.7.6     rprojroot_2.0.2   grid_4.0.5       
[36] cli_3.2.0         tools_4.0.5       magrittr_2.0.2    crayon_1.5.0      pkgconfig_2.0.3   ellipsis_0.3.2    xml2_1.3.3       
[43] reprex_2.0.1      assertthat_0.2.1  httr_1.4.2        rstudioapi_0.13   R6_2.5.1          compiler_4.0.5   ```
david-cortes commented 2 years ago

Thanks for the information. Looks like you have a very old compiler with bugs that have been fixed in newer versions.

In particular, there seems to be an issue with mixing the C <math.h> header (which R forcibly includes) with the C++ <cmath> header (which this library uses).

I’ll try to push a fix later today, but in the meantime, you could probably bypass the issue by installing a newer GCC (current version is 12, but probably version 5 or later would do).

david-cortes commented 2 years ago

I've pushed another update which I think might fix it this time - could you give it another try?

remotes::install_github("david-cortes/isotree")

Although, looking again at your configuration, I do see something fishy, particularly this line:

CPPFLAGS = -I/usr/local/include

That variable should normally be empty, and as it is right now, it instructs R to look for system headers in that directory, which might or might not match with the compiler that R is configured to use. Your computer might have different compilers or compiler versions installed in parallel (e.g. clang or gcc8), and the headers in that directory might not be the headers of the gcc4.8 compiler that your R installation is using, which is something that can cause this type of issues.