c++ - R包错误错误: ‘std::Rf_beta’ has not been declared #define beta Rf_beta

标签 c++ r c gcc

我正在尝试安装一个名为 dbarts 的 R 软件包。我在 rhel8 linux 机器上运行 R。但我在安装过程中看到以下错误。

我已经安装了 rhel8 linux 软件包 gcc、clang 和 clang-devel。

> install.packages('dbarts', lib = .Library.site)
trying URL 'https://packagemanager.rstudio.com/cran/2023-07-12/src/contrib/dbarts_0.9-23.tar.gz'
Content type 'binary/octet-stream' length 850972 bytes (831 KB)
==================================================
downloaded 831 KB

* installing *source* package ‘dbarts’ ...
** package ‘dbarts’ successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... gcc
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 gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking how to run the C preprocessor... gcc -E
checking whether the compiler supports GNU C++... yes
checking whether g++ -std=gnu++17 accepts -g... yes
checking for g++ -std=gnu++17 option to enable C++11 features... none needed
checking how to run the C++ preprocessor... g++ -std=gnu++17 -E
checking for C/C++ restrict keyword... no
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking whether byte ordering is bigendian... no
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for C compiler vendor... gnu
checking whether C compiler accepts ... yes
checking whether C compiler accepts -msse2... yes
checking whether C compiler accepts -msse4.1... yes
checking whether C compiler accepts -mavx... yes
checking whether C compiler accepts -mavx2... yes
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking whether gcc is Clang... no
checking whether pthreads work with "-pthread" and "-lpthread"... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking whether more special flags are required for pthreads... no
checking for PTHREAD_PRIO_INHERIT... yes
checking for cstdint... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for malloc.h... yes
checking for int64_t... yes
checking for uint64_t... yes
checking size of size_t... 8
checking alignment of void*... 8
checking for gettimeofday... yes
checking for clock_gettime... yes
checking for ffs... yes
checking for size_t... yes
checking for working alloca.h... yes
checking for alloca... yes
checking for working posix_memalign... yes
checking for snprintf... yes
checking if g++ supports namespace std... yes
checking whether snprintf is in std::... yes
checking for log1p... yes
checking whether log1p is in std::... no
configure: creating ./config.status
config.status: creating src/Makevars
config.status: creating src/config.hpp
config.status: creating src/dbarts/config.hpp
config.status: creating src/misc/config.h
config.status: creating src/external/config.h
config.status: creating inst/include/dbarts/types.hpp
config.status: creating src/include/misc/types.h
** libs
using C compiler: ‘gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-18)’
using C++ compiler: ‘g++ (GCC) 8.5.0 20210514 (Red Hat 8.5.0-18)’
g++ -std=gnu++17 -I"/opt/R/4.3.1/lib/R/include" -DNDEBUG -I../inst/include -Iinclude -pthread  -I/usr/local/include    -fpic  -g -O2  -c R_C_interface.cpp -o R_C_interface.o
g++ -std=gnu++17 -I"/opt/R/4.3.1/lib/R/include" -DNDEBUG -I../inst/include -Iinclude -pthread  -I/usr/local/include    -fpic  -g -O2  -c R_interface.cpp -o R_interface.o
g++ -std=gnu++17 -I"/opt/R/4.3.1/lib/R/include" -DNDEBUG -I../inst/include -Iinclude -pthread  -I/usr/local/include    -fpic  -g -O2  -c R_interface_common.cpp -o R_interface_common.o
g++ -std=gnu++17 -I"/opt/R/4.3.1/lib/R/include" -DNDEBUG -I../inst/include -Iinclude -pthread  -I/usr/local/include    -fpic  -g -O2  -c R_interface_crossvalidate.cpp -o R_interface_crossvalidate.o
In file included from include/external/stats.h:10,
                 from R_interface_crossvalidate.cpp:13:
/opt/R/4.3.1/lib/R/include/Rmath.h:210:15: error: ‘std::Rf_beta’ has not been declared
 #define beta  Rf_beta
               ^~~~~~~
make: *** [/opt/R/4.3.1/lib/R/etc/Makeconf:200: R_interface_crossvalidate.o] Error 1
ERROR: compilation failed for package ‘dbarts’
* removing ‘/opt/R/4.3.1/lib/R/site-library/dbarts’

The downloaded source packages are in
        ‘/opt/rtemp/Rtmpzomc18/downloaded_packages’
Warning message:
In install.packages("dbarts", lib = .Library.site) :
  installation of package ‘dbarts’ had non-zero exit status


最佳答案

该错误感觉可能是 R 的 stats header 与 C/C++ 库 header 之间不兼容。

自 C++17 起,std::beta() 现在的定义如 https://en.cppreference.com/w/cpp/numeric/special_functions/beta 中所述。 。我猜测 R 源中的这一行:

https://github.com/wch/r-source/blob/09c2fbdcab3fd4397e4e654f21222687ed71ef4b/src/include/Rmath.h0.in#L210

是造成麻烦的原因。幸运的是,您应该能够通过以下方法来避免这个问题:

#define R_NO_REMAP
#define R_NO_REMAP_RMATH

它可以包含在包的 src/Makevars 文件中,或者包含在您自己的 ~/.R/Makevars 文件中。 (如果该文件尚不存在,您可能需要创建该文件。)

关于c++ - R包错误错误: ‘std::Rf_beta’ has not been declared #define beta Rf_beta,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76755554/

相关文章:

c++ - 运行我的 C++ 代码给我一个空白的控制台

r - 讨厌的饼图箭头

r - 在向量中查找唯一的一组字符串,其中向量元素可以是多个字符串

c++ - C中的同步写操作

c - 带空格分隔符的strtok

c - Switch 语句不会重复计数

c++ - QThread内存泄漏

c++ - 两次使用 cin 时的意外行为

c++ - yaml-cpp 解析字符串

r - 读取的项目数不是带有 read.transactions 的列数的倍数