无法运行C++代码(主要是缺少包含文件(.h))。

问题描述 投票:1回答:1

我已经在R 3.6.3和最近的R 4.0中尝试了以下内容。我的版本是Xcode 11.4.1,并做了以下工作xcode-select --install 以确保我有命令行工具。

当一个R包必须在Rstudio中从源码编译时,我得到的错误是config.his not found。当我尝试Rcpp时,我也得到类似的错误(一些.h没有找到.例如math.h)。

如果有人有解决方法,请告诉我,谢谢。我搜索了不少关于这个问题的资料,但一直无法解决。

* installing *source* package ‘pkgbuild’ ...
** package ‘pkgbuild’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (pkgbuild)
* installing *source* package ‘rlang’ ...
** package ‘rlang’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I./lib/  -I/usr/local/include   -fPIC  -Wall -g -O2  -c capture.c -o capture.o
In file included from capture.c:1:
In file included from /Library/Frameworks/R.framework/Resources/include/Rinternals.h:44:
In file included from /Library/Frameworks/R.framework/Resources/include/R_ext/Arith.h:41:
In file included from /usr/local/include/math.h:8:
In file included from /usr/local/include/features.h:10:
/usr/local/include/forwards.h:10:10: fatal error: 'config.h' file not found
#include "config.h"
         ^~~~~~~~~~
1 error generated.
make: *** [capture.o] Error 1
ERROR: compilation failed for package ‘rlang’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rlang’
Warning in install.packages :
  installation of package ‘rlang’ had non-zero exit status
c++ r
1个回答
0
投票

我在一个专门针对R开发者的邮件列表上发布了类似的东西。经过一些讨论,很明显有冲突的头文件位于usrlocalinclude和usrlocallibrary中。这些*.h文件被选择,而不是与R相关的文件。

一个解决方法(有效)是创建一个名为 ~.R 的目录,然后在这个目录中,有一个 Makevars 文件,其中有以下一行。

CPPFLAGS = -isysroot LibraryDeveloperCommandLineToolsSDKsMacOSX.sdk。

第二个解决方案是重命名usrlocallibrary和usrlocalinclude,使这些文件在试图从C++源码编译或使用Rcpp包时,R无法使用。

希望这些解决方法能够帮助其他人,如果他们有类似的问题。

© www.soinside.com 2019 - 2024. All rights reserved.