RcppCore / RcppEigen

Rcpp integration for the Eigen templated linear algebra library
Other
110 stars 40 forks source link

Can not install RcppEigen, RcppEigen.h: No such file or directory #128

Closed pati-ni closed 1 year ago

pati-ni commented 1 year ago

I can't install RcppEigen in the latest R 4.3.1. It complains about the RcppEigen.h file

Here is the log:

trying URL 'https://mirrors.nics.utk.edu/cran/src/contrib/RcppEigen_0.3.3.9.3.tar.gz'
Content type 'application/x-gzip' length 1470790 bytes (1.4 MB)
==================================================
downloaded 1.4 MB

* installing *source* package ‘RcppEigen’ ...
** package ‘RcppEigen’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
using C compiler: ‘gcc (GCC) 13.1.1 20230429’
using C++ compiler: ‘g++ (GCC) 13.1.1 20230429’
g++ -std=gnu++17 -I"/usr/include/R/" -DNDEBUG  -I'/home/main/R/x86_64-pc-linux-gnu-library/4.3/Rcpp/include' -I/usr/local/include   -O3 -g -fpic  -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security         -fstack-clash-protection -fcf-protection -Wp,-D_GLIBCXX_ASSERTIONS -g -ffile-prefix-map=/build/r/src=/usr/src/debug/r -flto=auto -ffat-lto-objects  -c RcppEigen.cpp -o RcppEigen.o
RcppEigen.cpp:22:10: fatal error: RcppEigen.h: No such file or directory
   22 | #include <RcppEigen.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make: *** [/usr/lib64/R/etc/Makeconf:200: RcppEigen.o] Error 1
ERROR: compilation failed for package ‘RcppEigen’
* removing ‘/home/main/R/x86_64-pc-linux-gnu-library/4.3/RcppEigen’

The downloaded source packages are in
    ‘/tmp/RtmpTzupPl/downloaded_packages’
Warning message:
In install.packages("RcppEigen") :
  installation of package ‘RcppEigen’ had non-zero exit status

Here is my sessionInfo():

> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS:   /usr/lib/libblas.so.3.11.0
LAPACK: /usr/lib/liblapack.so.3.11.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] 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
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

time zone: America/New_York
tzcode source: system (glibc)

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

loaded via a namespace (and not attached):
[1] compiler_4.3.1 tools_4.3.1    pbdZMQ_0.3-9
eddelbuettel commented 1 year ago

Cannot reproduce, and would of course have heard from CRAN too if it was generalizable. Eg in a standard container that is Debian based:

edd@rob:~$ docker run --rm -ti r-base R

R version 4.2.3 (2023-03-15) -- "Shortstop Beagle"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> install.packages("RcppEigen")
install.packages("RcppEigen")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependency ‘Rcpp’

trying URL 'https://cloud.r-project.org/src/contrib/Rcpp_1.0.10.tar.gz'
Content type 'application/x-gzip' length 2936173 bytes (2.8 MB)
==================================================
downloaded 2.8 MB

trying URL 'https://cloud.r-project.org/src/contrib/RcppEigen_0.3.3.9.3.tar.gz'
Content type 'application/x-gzip' length 1470790 bytes (1.4 MB)
==================================================
downloaded 1.4 MB

* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/     -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4.2.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c api.cpp -o api.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/     -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4.2.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c attributes.cpp -o attributes.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/     -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4.2.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c barrier.cpp -o barrier.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/     -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4.2.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c date.cpp -o date.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/     -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4.2.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c module.cpp -o module.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/     -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4.2.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c rcpp_init.cpp -o rcpp_init.o
g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-z,relro -o Rcpp.so api.o attributes.o barrier.o date.o module.o rcpp_init.o -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/00LOCK-Rcpp/00new/Rcpp/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (Rcpp)
* installing *source* package ‘RcppEigen’ ...
** package ‘RcppEigen’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include'   -I../inst/include -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4.2.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c RcppEigen.cpp -o RcppEigen.o
[... 
     a million lines with noise compiler messages removed .
...]
gcc -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include'    -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4.2.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c init.c -o init.o
g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-z,relro -o RcppEigen.so RcppEigen.o RcppExports.o fastLm.o init.o -llapack -lblas -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/00LOCK-RcppEigen/00new/RcppEigen/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (RcppEigen)

The downloaded source packages are in
    ‘/tmp/Rtmpc992c4/downloaded_packages’
> 
eddelbuettel commented 1 year ago

Try editing PKG_CXXFLAGS = -I../inst/include in src/Makevars to make it PKG_CPPFLAGS = -I../inst/include. You can see in my build log that the -I../inst/include (that we need) is there C++14 use.

eddelbuettel commented 1 year ago

I very strongly suspect it is something with Arch, but I cannot put my finger on it. When I use this quick settings file ~/.R/Makevars to force g++-13 (as you have) and C++17 (as your build uses) it still works:

XTRAFLAGS=-Wno-ignored-attributes

CXXFLAGS=               $(DEBUG_OPTIM) -Wall -pipe $(PEDANTIC) $(XTRAFLAGS) $(LTO)

VER=-13
CC=gcc$(VER)
CXX=g++$(VER) -std=c++17

as we can see:

root@e13e6aea57a3:/tmp/RcppEigen# rm src/*.so src/*.o
root@e13e6aea57a3:/tmp/RcppEigen# R CMD INSTALL .
* installing to library ‘/usr/local/lib/R/site-library’
* installing *source* package ‘RcppEigen’ ...
** package ‘RcppEigen’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
using C compiler: ‘gcc-13 (Debian 13.1.0-6) 13.1.0’
using C++ compiler: ‘g++-13 (Debian 13.1.0-6) 13.1.0’
g++-13 -std=c++17 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/lib/R/site-library/Rcpp/include'    -I../inst/include -fpic   -Wall -pipe  -Wno-ignored-attributes  -c RcppEigen.cpp -o RcppEigen.o
g++-13 -std=c++17 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/lib/R/site-library/Rcpp/include'    -I../inst/include -fpic   -Wall -pipe  -Wno-ignored-attributes  -c RcppExports.cpp -o RcppExports.o
g++-13 -std=c++17 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/lib/R/site-library/Rcpp/include'    -I../inst/include -fpic   -Wall -pipe  -Wno-ignored-attributes  -c fastLm.cpp -o fastLm.o
gcc-13 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/lib/R/site-library/Rcpp/include'     -fpic  -g -O2 -ffile-prefix-map=/build/r-base-O3lIg6/r-base-4.3.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c init.c -o init.o
g++-13 -std=c++17 -shared -L/usr/lib/R/lib -Wl,-z,relro -o RcppEigen.so RcppEigen.o RcppExports.o fastLm.o init.o -llapack -lblas -lgfortran -lm -lquadmath -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/00LOCK-RcppEigen/00new/RcppEigen/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (RcppEigen)
root@e13e6aea57a3:/tmp/RcppEigen# 

That still uses the (current) rocker/r-base container to which I added g++-13 gfortan-13 r-cran-rcpp. (The latter only to no have had to build it, it's quick as seen above.)

pati-ni commented 1 year ago

Try editing PKG_CXXFLAGS = -I../inst/include in src/Makevars to make it PKG_CPPFLAGS = -I../inst/include. You can see in my build log that the -I../inst/include (that we need) is there C++14 use.

Yes, this was Arch related and also affected other packages with similar include errors. Adding PKG_CXXFLAGS = -I../inst/include to .R/Makevars fixed it. Thanks for the help

eddelbuettel commented 1 year ago

Thanks for confirming. Given that I am also the R maintainer for Debian: any idea what happened and how R (accidently) got built on Arch in a way that made the PKG_CXXFLAGS from src/Makevars be ignored?

pati-ni commented 1 year ago

Sorry for the delayed reply.

Actually the problem was system specific. In my ~/.R/Makevars I had PKG_CXXFLAGS = -O3 -g. It seems as if this overrides the package-specific options src/Makevars. I did not know that. No problem with the upstream distributions of R as far as I can tell.

eddelbuettel commented 1 year ago

That would do it -- in general do not set variable named PKG_* in ~/.R/Makevars. Everything named PKG_* belongs in the version in the package.

In ~/.R/Makevars only set (and specialise) what R has in its own $R_HOME/etc/Makeconf.