nimble-dev / nimble

The base NIMBLE package for R
http://R-nimble.org
BSD 3-Clause "New" or "Revised" License
160 stars 24 forks source link

failure to install under Red Hat Enterprise Linux #1415

Closed paciorek closed 6 months ago

paciorek commented 9 months ago

A user reported this error when trying to install nimble from source (the only option apparently) under RHEL. I've recreated with a Docker container (see steps at bottom).

g++ -std=gnu++17 -I"/opt/R/4.3.2/lib/R/include" -DNDEBUG -DR_NO_REMAP -I"../include"  -I/usr/local/include    -fpic  -O2  -c predefinedNimbleLists.cpp -o predefinedNimbleLists.o
<snip>
In file included from ../include/nimble/Utils.h:28,
                 from ../include/nimble/smartPtrs.h:25,
                 from ../include/nimble/predefinedNimbleLists.h:7,
                 from predefinedNimbleLists.cpp:4:
/opt/R/4.3.2/lib/R/include/Rmath.h:210:15: error: 'std::Rf_beta' has not been declared
 #define beta  Rf_beta
               ^~~~~~~

For reference, under Ubuntu, this is the compilation invocation:

g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -DR_NO_REMAP -I"../include"      -fpic  -O2 -ffile-prefix-map=/build/r-base-H0vbME/r-base-4.3.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c predefinedNimbleLists.cpp -o predefinedNimbleLists.o

There is some discussion of apparently the same issue here on StackOverflow. In trying some of the ideas in that post, such as moving math.h above Rmath.h and using R_NO_REMAP_RMATH I could sometimes (not always) get nimble to install, but then running the eigen() related test in test-nimbleLists.R, the same error with not finding std::Rf_beta would occur.

Some other notes:

  1. It's not clear to me why we have math.h and Rmath.h as includes in predefinedNimbleLists.cpp.
  2. Using --std=gnu++11 allows installation to occur.

To set up RHEL:

docker run -it --name test registry.access.redhat.com/ubi8/ubi:8.9 bash

dnf install gcc

# https://docs.posit.co/resources/install-r/
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
export R_VERSION=4.3.2
curl -O https://cdn.rstudio.com/r/centos-8/pkgs/R-${R_VERSION}-1-1.x86_64.rpm
yum install R-${R_VERSION}-1-1.x86_64.rpm

export PATH=/opt/R/${R_VERSION}/bin:${PATH}

## needed for igraph
yum install libxml2-devel
export PKG_CONFIG_PATH=/usr/lib64/pkgconfig

curl -O https://www.rpmfind.net/linux/centos/8-stream/PowerTools/x86_64/os/Packages/suitesparse-devel-4.4.6-11.el8.x86_64.rpm
curl -O https://www.rpmfind.net/linux/centos/8-stream/AppStream/x86_64/os/Packages/suitesparse-4.4.6-11.el8.x86_64.rpm
curl -O https://rpmfind.net/linux/centos/8-stream/AppStream/x86_64/os/Packages/tbb-2018.2-9.el8.x86_64.rpm

yum install tbb-2018.2-9.el8.x86_64.rpm
yum install suitesparse-4.4.6-11.el8.x86_64.rpm
yum install suitesparse-devel-4.4.6-11.el8.x86_64.rpm
yum install glpk
yum install gmp-devel

Rscript -e "install.packages('nimble')"
paciorek commented 9 months ago

It appears that the following will fix this.

1) move the math.h and Rmath.h to the top of the includes in predefinedNimblelist.cpp, mimicing nimIntegrate.cpp. This will allow nimble to build. 2) monkey with CPPincludes so that our generated code also has math.h and Rmath.h as the first includes. This will allow run-time compilation of the eigen example in test-nimbleLists.h.

I will follow that path on Monday or so. When I first attempted item 2 above I was unable to control the order of how the CPPincludes got put into our generated Cpp files so I need to better understand that.