编译R包时遇Eigen/Core #include <new>文件不存在错误求助
问题:R包安装失败,编译器无法识别
<new>头文件 设备信息
- Thinkpad系列笔记本
- Manjaro KDE系统(内核5.13)
- 全新安装的R 4.2
- 全新安装的RStudio
- 已按指定指南安装多个包(含rstan)
问题描述
在RStudio中安装R 4.2的多个包时(如安装brms依赖的mvtnorm、nleqslv),均出现相同编译错误:编译器无法识别RcppEigen目录下Eigen/Core头文件第82行的#include <new>语句,导致包安装失败。
已尝试操作
- 重新安装RcppEigen,问题未解决
- 搜索
include new相关问题,仅找到Arduino等特殊设备的类似案例
询问是否需要更换编译器,寻求解决方案。
编译日志
* installing *source* package ‘mvtnorm’ ... ** package ‘mvtnorm’ 解压完成并通过MD5校验 ** 使用分段安装 ** libs gcc -I"/usr/include/R/" -DNDEBUG -I"/home/jpapir/R/x86_64-pc-linux-gnu-library/4.2/Rcpp/include/" -I"/home/jpapir/R/x86_64-pc-linux-gnu-library/4.2/RcppEigen/include/" -I"/home/jpapir/R/x86_64-pc-linux-gnu-library/4.2/RcppEigen/include/unsupported" -I"/home/jpapir/R/x86_64-pc-linux-gnu-library/4.2/BH/include" -I"/home/jpapir/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders/include/src/" -I"/home/jpapir/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders/include/" -I"/home/jpapir/R/x86_64-pc-linux-gnu-library/4.2/RcppParallel/include/" -I"/home/jpapir/R/x86_64-pc-linux-gnu-library/4.2/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/home/jpapir/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -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 -flto=auto -ffat-lto-objects -c C_FORTRAN_interface.c -o C_FORTRAN_interface.o 从/home/jpapir/R/x86_64-pc-linux-gnu-library/4.2/RcppEigen/include/Eigen/Dense:1包含的文件中, 从/home/jpapir/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13, 从命令行: /home/jpapir/R/x86_64-pc-linux-gnu-library/4.2/RcppEigen/include/Eigen/Core:82:12: 致命错误:new:没有该文件或目录 82 | #include <new> | ^~~~~ 编译终止。 make: *** [/usr/lib64/R/etc/Makeconf:169 : C_FORTRAN_interface.o] 错误 1 ERROR: 编译包‘mvtnorm’失败 * 正在移除‘/home/jpapir/R/x86_64-pc-linux-gnu-library/4.2/mvtnorm’ Warning in install.packages : 包‘mvtnorm’的安装退出状态非零
解决办法
1. 安装完整C++开发环境
<new>是C标准库头文件,编译器找不到它大概率是缺少完整的C开发依赖。在Manjaro终端执行:
sudo pacman -S base-devel gcc-libs libstdc++
2. 强制R使用g++编译
部分情况下R的编译配置会误用C编译器处理C++代码,导致头文件缺失。在R中执行:
Sys.setenv(CXX = "g++") Sys.setenv(CC = "gcc") install.packages("mvtnorm")
3. 重置RcppEigen及依赖包
如果之前的安装有残留问题,完全卸载后重新安装:
remove.packages(c("RcppEigen", "mvtnorm", "brms")) install.packages("RcppEigen", type = "source") install.packages("brms")
4. 更新系统与编译器
你的内核版本5.13较旧,Manjaro作为滚动更新系统,建议更新整个系统确保依赖最新:
sudo pacman -Syu
更新完成后重启系统,再尝试安装R包。
5. 检查编译器版本冲突
若系统存在多版本gcc/g++,可能导致路径混乱。检查当前默认版本:
gcc --version g++ --version
若版本不一致,可通过软链接设置默认版本(以gcc12为例):
sudo ln -sf /usr/bin/gcc-12 /usr/bin/gcc sudo ln -sf /usr/bin/g++-12 /usr/bin/g++
内容的提问来源于stack exchange,提问作者user21048379
相关产品推荐
相关产品推荐

